HashDoS: how can worst case complexity of Hashtable be O(n^2)?

佐手、 提交于 2019-12-07 22:46:26

问题


By now many of you must have heard about HashDoS. The researchers who found this, claim in their video that the worst case complexity of Hastable is O(n^2). How can this be?


回答1:


The question is worded in an incorrect way. The researchers do not claim that "the worst case complexity of Hashtables is O(n^2)".

What they claim is that "The [...] complexity of inserting n elements into the table [...] goes to O(n^2)." So, the complexity of a single operation is O(n). Which makes sense: if all keys have the same hash, then they all go into the same bucket, which is just an array or a linked list, so it needs to be searched linearly.



来源:https://stackoverflow.com/questions/8677282/hashdos-how-can-worst-case-complexity-of-hashtable-be-on2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!