in reply to Re^3: mathematical proof
in thread mathematical proof
Incidentally if you look at the worst case performance of a hash that uses linked lists for the buckets, then the hash access is O(n) which means that building a hash with n buckets cannot be better than O(n*n). Which clearly loses to the array solution. Conditional logic to try and reduce the likelyhood of worst case performance cannot improve this fact unless you replace the linked list in the bucket with something else (like a btree).
Changing the structure of the buckets will make the average case hash access O(1) and worst case O(log(n)) but complicates the code and makes the constant for a hash access worse. People tend to notice the average case performance, and so do not make that change. Real example: when abuse of the hashing function showed up as a security threat in Perl, multiple options were considered. In the end rather than making the worst case performance better, it was decided to randomize the hashing algorithm so that attackers cannot predict what data sets will cause performance problems.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: mathematical proof
by JavaFan (Canon) on Feb 03, 2009 at 15:01 UTC | |
by tilly (Archbishop) on Feb 03, 2009 at 16:40 UTC | |
by ikegami (Patriarch) on Feb 03, 2009 at 17:10 UTC |