All mock tests are FREE till 31 December — register to save your progress

Consider a hash table of size 7 with starting index 0 and hash function (6x + 3) mod 4. Assuming the table is initially empty, which of the following is the content of the table when the sequence 1, 3, 8, 10, 5 is inserted using closed hashing (linear probing)? Here '_' denotes an empty location.

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: D. _, 1, 3, 8, 10, 5, _

Explanation

h(1) = 9 mod 4 = 1 → slot 1. h(3) = 21 mod 4 = 1 → collides, goes to 2. h(8) = 51 mod 4 = 3 → slot 3. h(10) = 63 mod 4 = 3 → goes to 4. h(5) = 33 mod 4 = 1 → probes 2, 3, 4 → slot 5. Table: _, 1, 3, 8, 10, 5, _.

More Data Structures and Algorithms questions