r/programming • u/martincmartin • Jul 14 '09
Dynamic Perfect Hashing: A hash table with constant time lookup in the worst case, and O(n) space.
http://en.wikipedia.org/wiki/Dynamic_perfect_hashing
17
Upvotes
5
u/martincmartin Jul 14 '09
To be clear (too bad I can't edit the title), the O(n) space is average (i.e. expected), not worse case. But the constant lookup time is worst case, since you only need to look in two buckets.
3
u/onezerozeroone Jul 14 '09
What's the tradeoff? Why isn't everyone using this, then?
3
u/kragensitaker Jul 15 '09
This sounds like it uses a lot of space, like several words of memory (on the order of three to ten) per value stored. Does it, in practice?
I'm a little bit confused by the relationship between the stub article and its sole reference. The Wikipedia article calls this technique "dynamic perfect hashing", but the PDF reference given calls it "perfect hashing", and the section about "dynamic perfect hashing" is a variant that supports adding and deleting keys.
(And this is aside from the usual meaning of "perfect hashing", which is more general: it just refers to collision-free hash functions, not this clever two-level scheme.)
0
u/thbb Jul 14 '09
stop the bullshit. You still have to compute the hashcode, which is O(log(n)). There's no universal solution for this type of issue. Personally, I'm fond of TST and their variations.