GATE CS 2021 Set 1 | Question 57
Algorithms › Hashing · MSQ · 2 marks · Answer: C
- Question 57Algorithmsmsq2 marksConsider a *dynamic* hashing approach for 4-bit integer keys: 1. There is a main hash table of size 4. 2. The 2 least significant bits of a key is used to index into the main hash table. 3. Initially, the main hash table entries are empty. 4. Thereafter, when more keys are hashed into it, to resolve collisions, the set of all keys corresponding to a main hash table entry is organized as a binary tree that grows on demand. 5. First, the 3rd least significant bit is used to divide the keys into left and right subtrees. 6. To resolve more collisions, each node of the binary tree is further sub-divided into left and right subtrees based on the 4th least significant bit. 7. A split is done only if it is needed, i.e., only when there is a collision. Consider the state of the hash table shown in the figure. Which of the following sequences of key insertions can cause the above state of the hash table (assume the keys are in decimal notation)?

- A.5, 9, 4, 13, 10, 7
- B.9, 5, 10, 6, 7, 1
- C.10, 9, 6, 7, 5, 13✓
- D.9, 5, 13, 6, 10, 14
Answer: C
Solution
Tracing each insertion sequence through the index (2 LSBs) and the on-demand splits (3rd then 4th LSB), only sequence (C) 10, 9, 6, 7, 5, 13 reproduces exactly the shown tree structure, with splits occurring only where collisions force them. - A.
More GATE PYQ on Hashing
All GATE CS Algorithms PYQ →Attempt GATE CS 2021 Set 1 in real GATE exam mode
Full paper with a timer, the GATE interface and a topic-wise analysis — free.
Create free account →