Consider a hash table of size \(π=10000\), and the hash function \(h(K) =β¦
2016
Consider a hash table of sizeΒ \(π=10000\), and the hash functionΒ \(h(K) = floor (m(KA \bmod 1))\) for \(A = ( \sqrt{5} β 1)/2\). The keyΒ 123456Β is mapped to location ______.
- A.
46
- B.
41
- C.
43
- D.
48
Attempted by 299 students.
Show answer & explanation
Correct answer: B
Key formula: h(K) = floor(m * frac(K * A)) where A = (sqrt(5) - 1)/2
Evaluate A approximately: A = (sqrt(5) - 1)/2 β 0.6180339887498948.
Compute K * A: 123456 * 0.6180339887498948 β 76300.00411512.
Take the fractional part: frac(123456 * A) β 0.00411512.
Multiply by m = 10000: 10000 * 0.00411512 β 41.150.
Apply floor: floor(41.150) = 41. Therefore the key 123456 is mapped to location 41.