The keys and are inserted into an initially empty hash table of length using open addressing with hash function and linear probing. What is the resultant hash table?
View worked solution
Answer: C
To find the resultant hash table, we insert the keys one by one into an initially empty hash table of size (with indices to ) using the hash function and linear probing to resolve collisions.
Let's trace the insertion of each key step-by-step:
- Insert 12:
. Slot is empty. Insert 12 at slot . - Insert 18:
. Slot is empty. Insert 18 at slot . - Insert 13:
. Slot is empty. Insert 13 at slot . - Insert 2:
. Slot is occupied by .
Probe slot : occupied by .
Probe slot : empty. Insert 2 at slot . - Insert 3:
. Slot is occupied by .
Probe slot : occupied by .
Probe slot : empty. Insert 3 at slot . - Insert 23:
. Slot is occupied.
Probe slot : occupied.
Probe slot : occupied.
Probe slot : empty. Insert 23 at slot . - Insert 5:
. Slot is occupied.
Probe slot : occupied.
Probe slot : empty. Insert 5 at slot . - Insert 15:
. Slot is occupied.
Probe slot : occupied.
Probe slot : occupied.
Probe slot : occupied by .
Probe slot : empty. Insert 15 at slot .
The final state of the hash table is:
| Index | Value |
|---|---|
| 0 | — |
| 1 | — |
| 2 | 12 |
| 3 | 13 |
| 4 | 2 |
| 5 | 3 |
| 6 | 23 |
| 7 | 5 |
| 8 | 18 |
| 9 | 15 |
This matches the table given in Option C.
Free practice · Your answers on this page are not saved.
