I'm implementing a priority queue and want to iterate through the list to insert at the right spot. In the documentation it states that C# List<T>.Item Property is O(1):
List<T>.Item Property
e.g.
int retrivedValue = myIntList[5];
How is this possible since add also is O(1)? It's like eating the cookie and still have it. Normal lists in my head have O(n) for accessing an element.


List<T>is a list in representation, as the documentation says, it represents a typed list of objects that can be accessed by index. Its elements can be accessed by index directly and does not require element-by-element traversal, ergo, it's time complexity to access an element is O(1). It's implemented internally as a dynamic array, the kind that doubles its size when it fills up (thanks to comments!).You may be confusing it with
LinkedList<T>, which is implemented as a linked list...