A hash table of length uses open addressing with hash function , and linear probing. After inserting values into an empty hash table, the table is shown as below
Which one of the following choices gives a possible order in which the key values could have been inserted in the table?
View worked solution
Answer: C
To find the correct insertion order, let us first compute the primary hash value for each key:
Now, we trace the insertion sequence given in Option C ():
- Insert 46: . Index 6 is empty, so 46 is placed at index 6.
- Insert 34: . Index 4 is empty, so 34 is placed at index 4.
- Insert 42: . Index 2 is empty, so 42 is placed at index 2.
- Insert 23: . Index 3 is empty, so 23 is placed at index 3.
- Insert 52: . Index 2 is occupied (by 42). Probing sequentially: index 3 is occupied (by 23), index 4 is occupied (by 34), index 5 is empty. So, 52 is placed at index 5.
- Insert 33: . Index 3 is occupied (by 23). Probing sequentially: indices 4, 5, and 6 are occupied. Index 7 is empty, so 33 is placed at index 7.
This sequence perfectly matches the final state of the hash table. Other options fail; for example, in Option A, inserting 52 before 23 would place 52 at index 3, which contradicts the final table.
Free practice · Your answers on this page are not saved.
