120 likes | 445 Views
Hashing – Reordering Schemes. 1. Open Addressing. All keys stored in the table On collision follow probe sequence Must visit all locations in the table Hash function takes key and probe number h(k,i) : K x {1,2,...} --> {0,1,...,N-1}. 2. Computing Probe Sequence.
E N D
Open Addressing • All keys stored in the table • On collision follow probe sequence • Must visit all locations in the table • Hash function takes key and probe numberh(k,i) : K x {1,2,...} --> {0,1,...,N-1} 2
Computing Probe Sequence • Linear probing: h(k,i) = [h'(k) + (i-1) * c] mod N • Double hashing: h(k,i) = [h'(k) + (i-1) *h''(k)] mod N 3
Comparing Approaches • Average number of probes needed to insert • Average number of probes needed to find • Average number of probes needed to determine a record is not in the table 4
Minimizing Probes Needed to Find • psl – probe sequence length for a key • lpsl – longest probe sequence length 5
Review – Linear Probing 0 1 2 3 4 5 6 7 8 9 10 psl 6
Open Addressing with Reordering • On insertion can move existing elements • Reordering Schemes • Cuchoo hashing • Brent's method • Binary Tree Hashing • Optimal Hashing • Min-Max Hashing • Robin Hood Hashing 7
Brent's Method • On collision • Consider moving both new and existing element • Add psl of two element for each option. • Choose the one with the smallest added psl 0 1 2 3 4 5 6 7 8 9 10 psl 8
Brent's Method - Continued 0 1 2 3 4 5 6 7 8 9 10 psl 9
Binary Tree Hashing • Consider moving any key along the probe sequence • Build decision tree. At each index • Branch left to move the 'new' element • Branch right to move the existing element 10
Binary Tree Hashing - Example 0 1 2 3 4 5 6 7 8 9 10 psl 11