What does “O(1) access time” mean?

后端 未结 16 2273
栀梦
栀梦 2020-11-28 18:21

I have seen this term \"O(1) access time\" used to mean \"quickly\" but I don\'t understand what it means. The other term that I see with it in the same context is \"O(n) ac

16条回答
  •  天涯浪人
    2020-11-28 18:46

    The easiest way to differentiate O(1) and O(n) is comparing array and list.

    For array, if you have the right index value, you can access the data instantly. (If you don't know the index and have to loop through the array, then it won't be O(1) anymore)

    For list, you always need to loop through it whether you know the index or not.

提交回复
热议问题