Why hashmap lookup is O(1) i.e. constant time?

前端 未结 3 2116
借酒劲吻你
借酒劲吻你 2020-11-30 01:12

If we look from Java perspective then we can say that hashmap lookup takes constant time. But what about internal implementation? It still would have to search through parti

3条回答
  •  隐瞒了意图╮
    2020-11-30 01:40

    To follow up on templatetypedef's comments as well:

    The constant time implementation of a hash table could be a hashmap, with which you can implement a boolean array list that indicates whether a particular element exists in a bucket. However, if you are implementing a linked list for your hashmap, the worst case would require you going through every bucket and having to traverse through the ends of the lists.

提交回复
热议问题