What is the Big O of hashing with buckets?

  • A: O(1)
  • B: O(log n)
  • C: O(n) but you can make it very fast
  • D: O(n log n)
  • E: O(n2)

    Answer: C

    The formal answer is O(n) due to the time to search linearly through the linked list that is used for a bucket.

    In reality, though, the average time is n / (2 * nb) where nb is the number of buckets. By making the number of buckets large enough, say n / 10, we can make the search time small enough to be considered constant.

    Contents    Page-10    Prev    Next    Page+10    Index