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

后端 未结 16 2113
栀梦
栀梦 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:37

    According to my perspective,

    O(1) means time to execute one operation or instruction at a time is one, in time complexity analysis of algorithm for best case.

    0 讨论(0)
  • 2020-11-28 18:38

    Introduction to Algorithms: Second Edition by Cormen, Leiserson, Rivest & Stein says on page 44 that

    Since any constant is a degree-0 polynomial, we can express any constant function as Theta(n^0), or Theta(1). This latter notation is a minor abuse, however, because it is not clear what variable is tending to infinity. We shall often use the notation Theta(1) to mean either a constant or a constant function with respect to some variable. ... We denote by O(g(n))... the set of functions f(n) such that there exist positive constants c and n0 such that 0 <= f(n) <= c*g(n) for all n >= n0. ... Note that f(n) = Theta(g(n)) implies f(n) = O(g(n)), since Theta notation is stronger than O notation.

    If an algorithm runs in O(1) time, it means that asymptotically doesn't depend upon any variable, meaning that there exists at least one positive constant that when multiplied by one is greater than the asymptotic complexity (~runtime) of the function for values of n above a certain amount. Technically, it's O(n^0) time.

    0 讨论(0)
  • 2020-11-28 18:45

    It means that access time is constant. Whether you're accessing from 100 or 100,000 records, the retrieval time will be the same.

    In contrast, O(n) access time would indicate that the retrieval time is directly proportional to the number of records you're accessing from.

    0 讨论(0)
  • 2020-11-28 18:46

    O(1) means the time to access something is independent of the number of items in the collection.

    O(N) would mean the time to access an item is a proportional to the number (N) of items in the collection.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-28 18:48

    O(1) means Random Access. In any Random Access Memory, the time taken to access any element at any location is the same. Here time can be any integer, but the only thing to remember is time taken to retrieve the element at (n-1)th or nth location will be same(ie constant).

    Whereas O(n) is dependent on the size of n.

    0 讨论(0)
提交回复
热议问题