Consider a hash table of size seven, with starting index zero, and a hash function . Assuming the hash table is initially empty, which of the following is the contents of the table when the sequence is inserted into the table using closed hashing? Note that − denotes an empty location in the table.
View worked solution
Answer: B
We are given a hash table of size (with indices to ) and the hash function:
Since "closed hashing" (also known as open addressing) is used, we resolve collisions using linear probing, where we search sequentially for the next available slot: for .
Let's insert the keys step-by-step into an initially empty table:
-
Insert :
.
Slot is empty. Place at index .
Table state:[1, -, -, -, -, -, -] -
Insert :
.
Slot is empty. Place at index .
Table state:[1, -, -, -, -, -, 3] -
Insert :
.
Slot is occupied by (collision).
Using linear probing, we try the next slot: .
Slot is empty. Place at index .
Table state:[1, 8, -, -, -, -, 3] -
Insert :
.
Slot is occupied by (collision).
Probing sequence:- Try slot (occupied by )
- Try slot (occupied by )
- Try slot (empty)
Table state:[1, 8, 10, -, -, -, 3]
Thus, the final contents of the hash table are , −, −, −, , which matches option B.
Free practice · Your answers on this page are not saved.
