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 11–15 of 19
Consider a hash table with 100 slots. Collisions are resolved using chaining. Assuming simple uniform hashing, what is the probability that the first 3 slots are unfilled after the first 3 insertions?
Answer: (A)
In chaining, every key goes to any one of the 100 slots, and each key is independent of the others. So the probability that a key does not land in the first 3 slots is 97/100.
For 3 insertions, the probability is:
Answer: (97 97 97) /
For 3 insertions, the probability is:
Answer: (97 97 97) /
A hash table of length 10 uses open addressing with hash function h(k)=k mod 10, and linear probing. After inserting 6 values into an empty hash table, the table is as shown below
How many different insertion sequences of the key values using the same hash function and linear probing will result in the hash table shown above?
How many different insertion sequences of the key values using the same hash function and linear probing will result in the hash table shown above?
Answer: (C)
Checking each key:
- 42, 23, 34 and 46 sit in their home slots.
- 52 (home 2) landed in slot 5, so 42, 23, 34 come before it.
- 33 (home 3) landed in slot 7, so it is last.
Keys 42, 23, 34 can go in any order, then 52: 3! = 6 ways. Place 46 in any of 5 positions: 5 ways.
6 5 = 30
Answer: 30
- 42, 23, 34 and 46 sit in their home slots.
- 52 (home 2) landed in slot 5, so 42, 23, 34 come before it.
- 33 (home 3) landed in slot 7, so it is last.
Keys 42, 23, 34 can go in any order, then 52: 3! = 6 ways. Place 46 in any of 5 positions: 5 ways.
6 5 = 30
Answer: 30
A hash table of length 10 uses open addressing with hash function h(k)=k mod 10, and linear probing. After inserting 6 values into an empty hash table, the table is as shown below
Which one of the following choices gives a possible order in which the key values could have been inserted in the table?
Which one of the following choices gives a possible order in which the key values could have been inserted in the table?
Answer: (C)
Check the order 46, 34, 42, 23, 52, 33:
- 46 6, 34 4, 42 2, 23 3
- 52: slots 2, 3, 4 are full, so 5
- 33: slots 3, 4, 5, 6 are full, so 7
This gives the table shown. (In the other options, 52 or 33 ends up in a wrong slot.)
Answer: 46, 34, 42, 23, 52, 33
- 46 6, 34 4, 42 2, 23 3
- 52: slots 2, 3, 4 are full, so 5
- 33: slots 3, 4, 5, 6 are full, so 7
This gives the table shown. (In the other options, 52 or 33 ends up in a wrong slot.)
Answer: 46, 34, 42, 23, 52, 33
The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table of length 10 using open addressing with hash function h(k) = k mod 10 and linear probing. What is the resultant hash table?
Answer: (C)
Linear probing: if slot is full, try the next slot, then the next, wrapping around at the end of the table.
12 goes to slot 2. 18 goes to slot 8. 13 goes to slot 3.
2: slot 2 is full, so try 3 (full), then 4. It goes to slot 4.
3: slots 3 and 4 are full, so it goes to slot 5.
23: slots 3, 4, 5 are full, so it goes to slot 6.
5: slots 5 and 6 are full, so it goes to slot 7.
15: slots 5, 6, 7 are full and slot 8 holds 18, so it goes to slot 9.
Final table: slot 2 = 12, 3 = 13, 4 = 2, 5 = 3, 6 = 23, 7 = 5, 8 = 18, 9 = 15. This is table C. Tables A and B hold only 4 of the 8 keys, and D puts several keys in one slot, which is chaining, not open addressing.
Answer: (C)
12 goes to slot 2. 18 goes to slot 8. 13 goes to slot 3.
2: slot 2 is full, so try 3 (full), then 4. It goes to slot 4.
3: slots 3 and 4 are full, so it goes to slot 5.
23: slots 3, 4, 5 are full, so it goes to slot 6.
5: slots 5 and 6 are full, so it goes to slot 7.
15: slots 5, 6, 7 are full and slot 8 holds 18, so it goes to slot 9.
Final table: slot 2 = 12, 3 = 13, 4 = 2, 5 = 3, 6 = 23, 7 = 5, 8 = 18, 9 = 15. This is table C. Tables A and B hold only 4 of the 8 keys, and D puts several keys in one slot, which is chaining, not open addressing.
Answer: (C)
Consider a hash table of size 11 that uses open addressing with linear probing. Let h(k)=kmod 11 be the hash function used. A sequence of records with keys
43 36 92 87 11 4 71 13 14
is inserted into an initially empty hash table, the bins of which are indexed from zero to ten. What is the index of the bin into which the last record is inserted?
43 36 92 87 11 4 71 13 14
is inserted into an initially empty hash table, the bins of which are indexed from zero to ten. What is the index of the bin into which the last record is inserted?
Answer: (D)
With and linear probing (try the next slot, wrapping from 10 to 0):
- 43: , so slot 10.
- 36: 3, so slot 3.
- 92: 4, so slot 4.
- 87: 10 is full, so slot 0.
- 11: 0 is full, so slot 1.
- 4: 4 is full, so slot 5.
- 71: is full, so slot 6.
- 13: , so slot 2.
- 14: . Slots 3, 4, 5 and 6 are full, so slot 7.
Final hash table:
Answer: (D)
Keep practising