patternMinor
Using hash tables instead of lists for buckets in hash tables
Viewed 0 times
tablesbucketshashinsteadusingforlists
Problem
Say instead of using a linked list as buckets for a hash table of size $m$, we use another hash table of size $p$ as buckets this time. What would be the average case for this problem?
I looked up perfect hashing and I got a very close algorithm, and it is $O(1)$. Can someone please clarify?
I looked up perfect hashing and I got a very close algorithm, and it is $O(1)$. Can someone please clarify?
Solution
Using a hash table with $n$ buckets and a hash function $h_n : S \rightarrow \{0, 1, ..., n - 1\}$ , where each bucket is a hash table with $m$ buckets and a hash function $h_m : S \rightarrow \{0, 1, ..., m - 1\}$, is equivalent to a hash table wit $nm$ buckets and a hash function $h_{nm} : S \rightarrow \{0, 1, 2, ..., nm - 1\}$ where $h_{nm}(x) = mh_n(x) + h_m(x)$. In other words, using more than one level has no effect whatsoever on the complexity: it's the same as a for a garden-variety hash table.
Perfect hashing is a completely separate issue.
Perfect hashing is a completely separate issue.
Context
StackExchange Computer Science Q#2613, answer score: 6
Revisions (0)
No revisions yet.