Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

20
  • 8
    Allow me to just say: fantastic answer.
    – CRThaze
    Commented Jan 5, 2017 at 21:20
  • @Tony Delroy Thanks for the amazing answer. I still have one open point in my mind though. You say that even if there are 100 million buckets,lookup time would be O(1) with load factor 1 and a cryptographic strength hash function. But what about finding the right bucket in 100 million? Even if we have all the buckets sorted,isn't it O(log100.000.000)? How can finding the bucket be O(1) ?
    – selman
    Commented Dec 21, 2018 at 10:14
  • @selman: your question doesn't provide many details to explain why you think it might be O(log100,000,000), but you do say "even if we have all the buckets sorted" - keep in mind that values in hash table buckets are never "sorted" in the usual sense: which value appears in which bucket is determined by applying the hash function to the key. Thinking the complexity is O(log100,000,000) implies you imagine doing a binary search through sorted buckets, but that's not how hashing works. Maybe read a few of the other answers and see if it starts to make more sense. Commented Dec 26, 2018 at 12:08
  • @TonyDelroy Indeed,"sorted buckets" are the best-case scenario that I imagine. Hence O(log100,000,000) . But if this is not the case,how can the application find related bucket among millions? Does hash function generate a memory location somehow?
    – selman
    Commented Dec 27, 2018 at 10:01
  • 1
    @selman: because computer memory allows constant time "random access": if you can calculate a memory address you can retrieve the memory contents without having to have accessed memory in other parts of the array. So, whether you access the first bucket, the last bucket, or a bucket anywhere in between, it will have the same performance characteristics (loosely, take the same amount of time, albeit subject to CPU L1/L2/L3 memory caching impacts but they only work to help you quickly re-access recently accessed or coincidentally nearby buckets, and can be ignored for big-O analysis). Commented Dec 28, 2018 at 8:37