Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can List<T>.Item Property be O(1)? Typo?

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.

like image 895
Johan Holtby Avatar asked Apr 03 '14 04:04

Johan Holtby


1 Answers

The standard List type is backed by an internal array with O(1) access performance.

List does not use a linked list implementation.

like image 148
user2864740 Avatar answered Oct 01 '22 23:10

user2864740