Worse case time complexity put/get HashMap

前端 未结 5 1979
后悔当初
后悔当初 2021-02-10 22:41

What is the worst case time complexity of an Hashmap when the hashcode of it\'s keys are always equal.

In my understanding: As every key has the same hashcode it will al

5条回答
  •  无人及你
    2021-02-10 23:33

    When inserting, it doesn't matter where in the bucket you put it, so you can just insert it anywhere, thus insertion is O(1).

    Lookup is O(n) because you will have to loop through each object and verify that it is the one you were looking for (as you've stated).

提交回复
热议问题