Hash Tables · Programming, Data Structures and Algorithms
2 questions · asked in 2 of 3 years (2024–2026)
MCQ 21-mark 2
2024Questions per year2026
Questions 1–2 of 2
Consider a hash table of size 10 with indices , with the hash function
,
where linear probing is used to handle collisions. The hash table is initially empty and then the following sequence of keys is inserted into the hash table: 1, 4, 5, 6, 14, 15. The indices where the keys 14 and 15 are stored are, respectively:
,
where linear probing is used to handle collisions. The hash table is initially empty and then the following sequence of keys is inserted into the hash table: 1, 4, 5, 6, 14, 15. The indices where the keys 14 and 15 are stored are, respectively:
Answer: (D)
Hash function with linear probing (if a slot is taken, try the next slot, wrapping around).
Key 1: , goes to slot 3.
Key 4: , goes to slot 2.
Key 5: , goes to slot 5.
Key 6: , goes to slot 8.
Key 14: . Slot 2 is taken by 4, slot 3 is taken by 1, slot 4 is free. So 14 goes to slot .
Key 15: . Slot 5 is taken by 5, slot 6 is free. So 15 goes to slot .
Keys 14 and 15 are at indices 4 and 6.
Answer: (D)
Key 1: , goes to slot 3.
Key 4: , goes to slot 2.
Key 5: , goes to slot 5.
Key 6: , goes to slot 8.
Key 14: . Slot 2 is taken by 4, slot 3 is taken by 1, slot 4 is free. So 14 goes to slot .
Key 15: . Slot 5 is taken by 5, slot 6 is free. So 15 goes to slot .
Keys 14 and 15 are at indices 4 and 6.
Answer: (D)
Consider performing uniform hashing on an open address hash table with load factor , where elements are stored in the table with slots. The expected number of probes in an unsuccessful search is at most .
Inserting an element in this hash table requires at most _________ probes, on average.
Inserting an element in this hash table requires at most _________ probes, on average.
Answer: (B)
Correct Answer:
Reason: To insert a value, we must first search for a free slot in the hash table. This is the same as an unsuccessful search. The expected number of probes for that is given in the question as
Keep practising