GateAI
Searching, Sorting and Hashing

GATE CSE 2021 Set 1 · Q47

MSQ2 marksMedium

Time

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 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 3rd3^{\text{rd}} 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 4th4^{\text{th}} least significant bit. 7. A split is done only if it is needed, i.e., only when there is a collision. Consider the following state of the hash table. Which of the following sequences of key insertions can cause the above state of the hash table (assume the keys are in decimal notation)?

GATE CSE 2021 Set 1 Q47 diagram

Select all that applyOne or more correct

Pick every correct option

Solution

Step-by-step verified solution

Official answer: C) 10, 9, 6, 7, 5, 13

Searching, Sorting and Hashing

Let each 4-bit key be represented as b4b3b2b1b_4 b_3 b_2 b_1, where b1b_1 is the least significant bit (LSB) and b4b_4 is the most significant bit (4th4^{\text{th}} LSB).

From the given hash table structure:

  1. Index 00: Empty (no keys hashed to bucket 00).

  2. Index 11: Exactly 11 key hashed to 11 (no split occurred).

  3. Index 10: Exactly 22 keys hashed to 10, one having b3=0b_3 = 0 and the other having b3=1b_3 = 1 (causing a single split at level 1).

  4. Index 01: Exactly 33 keys hashed to 01:

    • One key with b3=0b_3 = 0 (left branch, no further split).

    • Two keys with b3=1b_3 = 1, which collide on b3b_3 and split on b4b_4 into b4=0b_4 = 0 and b4=1b_4 = 1.

Let's evaluate the options by converting each key to 4-bit binary:

  • Option (A): Keys {5,9,4,13,10,7}\{5, 9, 4, 13, 10, 7\}

    • 4=010024 = 0100_2 hashes to bucket 00. However, bucket 00 is empty. Thus, (A) is incorrect.

  • Option (B): Keys {9,5,10,6,7,1}\{9, 5, 10, 6, 7, 1\}

    • Keys hashing to 01 are 9=100129 = 1001_2 (b3=0b_3=0), 5=010125 = 0101_2 (b3=1b_3=1), and 1=000121 = 0001_2 (b3=0b_3=0).

    • Here, two keys have b3=0b_3=0 (99 and 11), which would cause the left subtree (b3=0b_3=0) to split on b4b_4. But in the given diagram, the right subtree (b3=1b_3=1) is split. Thus, (B) is incorrect.

  • Option (C): Keys {10,9,6,7,5,13}\{10, 9, 6, 7, 5, 13\}

    • 10=10102  ⟹  10 = 1010_2 \implies bucket 10, b3=0b_3=0

    • 6=01102  ⟹  6 = 0110_2 \implies bucket 10, b3=1b_3=1 (two keys in 10, one with b3=0b_3=0 and one with b3=1b_3=1)

    • 7=01112  ⟹  7 = 0111_2 \implies bucket 11, single key

    • 9=10012  ⟹  9 = 1001_2 \implies bucket 01, b3=0b_3=0

    • 5=01012  ⟹  5 = 0101_2 \implies bucket 01, b3=1,b4=0b_3=1, b_4=0

    • 13=11012  ⟹  13 = 1101_2 \implies bucket 01, b3=1,b4=1b_3=1, b_4=1

    • Keys 55 and 1313 share b3=1b_3=1 and split on b4b_4, which perfectly matches the given tree at bucket 01.

    • Bucket 00 remains empty.

    Thus, (C) is correct.

  • Option (D): Keys {9,5,13,6,10,14}\{9, 5, 13, 6, 10, 14\}

    • 6=011026 = 0110_2, 10=1010210 = 1010_2, and 14=1110214 = 1110_2 all hash to bucket 10, requiring 3 keys and another split at 10, which does not match the diagram. Thus, (D) is incorrect.

Therefore, only (C) produces the given state.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Searching, Sorting and Hashing previous year question is Q47 of the GATE CSE 2021 Set 1 paper. Find more GATE CSE PYQs on Searching, Sorting and Hashing in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Searching, Sorting and Hashing PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Searching, Sorting and Hashing in GATE CSE

Searching, Sorting and Hashing has 27 GATE CSE PYQs across 20 papers from 2012 to 2026. This is the only 2-mark MSQ among them, and GATE CSE 2021 Set 1 has 2.

How GATE tests Searching, Sorting and Hashing

More from GATE CSE 2021 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2021 Set 1 · Q47 · MSQ

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 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 following state of the hash table. Which of the following sequences of key insertions can cause the above state of the hash table (assume the keys are in decimal notation)?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.