且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更糟的情况下时间复杂性把/得到HashMap

更新时间:2022-10-14 23:05:05

Yes, in the worst case your hash map will degenerate into a linked list and you will suffer an O(N) penalty for lookups, as well as inserts and deletions, both of which require a lookup operation (thanks to the comments for pointing out the mistake in my earlier answer).

There are some ways of mitigating the worst-case behavior, such as by using a self-balancing tree instead of a linked list for the bucket overflow - this reduces the worst-case behavior to O(logn) instead of O(n).

相关阅读

技术问答最新文章