![]() ![]() ![]() The rehash operation, which is O(n), can at most happen after n/2 ops, which are all assumed O(1): Thus when you sum the average time per op, you get : (n*O(1) + O(n)) / n) = O(1).It is very rare that many items will be hashed to the same key [if you chose a good hash function and you don't have too big load balance.However, it is said to be O(1) average and amortized case because: Once a hash table has passed its load balance - it has to rehash.If too many elements were hashed into the same key: looking inside this key may take O(n) time.Hash tables suffer from O(n) worst time complexity due to two reasons: Hash tables are O(1) average and amortized case complexity, however it suffers from O(n) worst case time complexity. 1,466 8 8 gold badges 22 22 silver badges 34 34 bronze badges 5 Answers ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |