GATE CS 2021 · Set-1 · Indexing (B-trees, B+ trees, Hash Indexing)

MSQ · 2 marks · Problem DBMS-INDX-0042

Consider 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 are 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 (a 0 bit goes left, a 1 bit goes right).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 (again 0 left, 1 right).7. A split is done only if it is needed, i.e., only when there is a collision.The hash table is now in the following state (a "slot" holds one key):Entry 00: empty.Entry 01: split on the 3rd bit; its left child is a slot holding one key, and its right child is split again on the 4th bit into two slots, each holding one key.Entry 10: split on the 3rd bit into two slots, each holding one key.Entry 11: a single slot holding one key (no split).Which of the following sequences of key insertions can cause the above state of the hash table (assume the keys are in decimal notation)?
  1. A
    5,9,4,13,10,7
  2. B
    9,5,10,6,7,1
  3. C
    10,9,6,7,5,13
  4. D
    9,5,13,6,10,14

Solve it on GATE DA practice →More Storage & Indexing problems

Show the worked solution\[\boxed{\text{entry} = k \bmod 4,\quad \text{then bit } 3,\ \text{then bit } 4 \text{ (only on collision)}}\](A) \(5, 9, 4, 13, 10, 7\): \(4 = 0100\) lands in entry 00, which must be empty — incorrect.(B) \(9, 5, 10, 6, 7, 1\): entry 01 gets \(9 = 1001, 5 = 0101, 1 = 0001\). On bit 3, \(9\) and \(1\) go left and \(5\) right, so the left child splits again — the wrong side of entry 01 is split — incorrect.(C) \(10, 9, 6, 7, 5, 13\): entry 01 gets \(9, 5, 13\); bit 3 sends \(9\) left and \(5 = 0101, 13 = 1101\) right, which split on bit 4 into \(5\) and \(13\). Entry 10 gets \(10 = 1010\) (left) and \(6 = 0110\) (right). Entry 11 gets only \(7\). Entry 00 stays empty — correct.(D) \(9, 5, 13, 6, 10, 14\): entry 11 stays empty and entry 10 (\(10, 6, 14\)) needs a second split — incorrect.Answer: C

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com