ProgrammingHard
Keys 8, 16, 24 and 32 are hashed with h(k) = k % 8 and then with h(k) = k % 7. Which statement is correct?
- A. They all collide at slot 0 under both hashes
- B. They collide only under mod 7
- C. They land in distinct slots under both hashes
- D. They all collide at slot 0 with mod 8 but land in distinct slots 1 to 4 with mod 7
Correct answer: D. They all collide at slot 0 with mod 8 but land in distinct slots 1 to 4 with mod 7
Multiples of 8 all become 0 under mod 8, which is why a power-of-two table size needs a good mixing function. Mod 7 separates them into slots 1, 2, 3 and 4.
More C Programming questions
- With 10^5 keys and a load factor of at most 0.5, what is the smallest power-of-two table size that works?
- Keys 13 and 23 are inserted with linear probing into a table of size 10 with h(k) = k % 10. In which slot does 23 land?
- Keys 6, 1 and 11 are inserted with linear probing into a table of size 5, h(k) = k % 5. In which order do the keys appear when the table…
- With chaining, what is the expected number of nodes examined by an unsuccessful search when the load factor is 1.5?
- A hash table with 10 buckets receives 11 keys. What is the minimum number of collisions guaranteed?
- Which C code correctly inserts a node n at the front of bucket h of an array of struct node table[]?