Hashing · Data Structures
19 questions · asked in 14 of 27 years (2000–2026)
MCQ 13 · MSQ 2 · NAT 41-mark 10 · 2-mark 9
2000Questions per year2026
Questions 6–10 of 19
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)?
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)?
One or more options are correct.
Answer: (C)
State of the table: index 00 is empty. Index 01 has 3 keys: one with 3rd bit 0, and two with 3rd bit 1 that split on the 4th bit. Index 10 has 2 keys, with 3rd bit 0 and 1. Index 11 has 1 key.
Option C: 10, 9, 6, 7, 5, 13
- 10 = 1010 10, bit3 = 0; 6 = 0110 10, bit3 = 1. True
- 9 = 1001 01, bit3 = 0; 5 = 0101 and 13 = 1101 01, bit3 = 1, split on bit4 (0 and 1). True
- 7 = 0111 11. True
The others fail: (A) puts 4 index 00; (B) has 1 and 9 colliding with bit3 = 0; (D) has 6 and 14 colliding and nothing in 11.
Answer: 10, 9, 6, 7, 5, 13
Option C: 10, 9, 6, 7, 5, 13
- 10 = 1010 10, bit3 = 0; 6 = 0110 10, bit3 = 1. True
- 9 = 1001 01, bit3 = 0; 5 = 0101 and 13 = 1101 01, bit3 = 1, split on bit4 (0 and 1). True
- 7 = 0111 11. True
The others fail: (A) puts 4 index 00; (B) has 1 and 9 colliding with bit3 = 0; (D) has 6 and 14 colliding and nothing in 11.
Answer: 10, 9, 6, 7, 5, 13
Consider a double hashing scheme in which the primary hash function is , and the secondary hash function is . Assume that the table size is 23. Then the address returned by probe 1 in the probe sequence (assume that the probe sequence begins at probe 0) for key value k=90 is_____________.
Answer: 13
Compute both hash values:
- Primary hash:
- Secondary hash:
Probe formula for probe i: . Value for probe 1:
Answer: 13
- Primary hash:
- Secondary hash:
Probe formula for probe i: . Value for probe 1:
Answer: 13
Which one of the following hash functions on integers will distribute keys most uniformly over 10 buckets numbered 0 to 9 for i ranging from 0 to 2020?
Answer: (B)
Only the last digit of matters for .
(B) The last digits of for last digits 0 to 9 are 0, 1, 8, 7, 4, 5, 6, 3, 2, 9. Every bucket occurs once, so the keys spread evenly over all 10 buckets.
(A) The last digit of a square is only 0, 1, 4, 5, 6 or 9, so 4 buckets are never used.
(C) , so it is the same as (A).
(D) , which is always even, so the odd buckets are never used. In fact only buckets 0, 2 and 8 are used.
Answer: (B)
(B) The last digits of for last digits 0 to 9 are 0, 1, 8, 7, 4, 5, 6, 3, 2, 9. Every bucket occurs once, so the keys spread evenly over all 10 buckets.
(A) The last digit of a square is only 0, 1, 4, 5, 6 or 9, so 4 buckets are never used.
(C) , so it is the same as (A).
(D) , which is always even, so the odd buckets are never used. In fact only buckets 0, 2 and 8 are used.
Answer: (B)
Given a hash table T with 25 slots that stores 2000 elements, the load factor for T is ____________.
Answer: 80
Load factor formula and value:
Answer: 80
Answer: 80
Consider a hash table with 9 slots. The hash function is h(k)=k mod 9. The collisions are resolved by chaining. The following 9 keys are inserted in the order: 5, 28, 19, 15, 20, 33, 12, 17, 10. The maximum, minimum, and average chain lengths in the hash table, respectively, are
Answer: (A)
Find each key's slot using k mod 9: 5 5, 28 1, 19 1, 15 6, 20 2, 33 6, 12 3, 17 8, 10 1.
Chain lengths: slot 1 has 3, slot 6 has 2, slots 2, 3, 5 and 8 have 1 each, and slots 0, 4 and 7 have 0.
The maximum is 3, the minimum is 0, and the average is 9/9 = 1.
Answer: 3, 0, and 1
Chain lengths: slot 1 has 3, slot 6 has 2, slots 2, 3, 5 and 8 have 1 each, and slots 0, 4 and 7 have 0.
The maximum is 3, the minimum is 0, and the average is 9/9 = 1.
Answer: 3, 0, and 1
Keep practising