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 16–19 of 19
Consider a hash function that distributes keys uniformly. The hash table size is 20. After hashing of how many keys will the probability that any new key hashed collides with an existing one exceed 0.5.
Answer: (B)
The question can be read two ways. If it means the chance that the next key hits an already-filled slot, that chance is for keys in the table. It passes 0.5 only at . The reading that fits the choices 5, 6, 7 and 10 is the chance that at least one collision has happened among the first keys.
P(no collision in keys) .
We need P(collision) P(no collision) , that is P(no collision) .
: , so P(collision) , which is not enough.
: , so P(collision) .
So .
Answer: (B)
P(no collision in keys) .
We need P(collision) P(no collision) , that is P(no collision) .
: , so P(collision) , which is not enough.
: , so P(collision) .
So .
Answer: (B)
Consider a hash table of size seven, with starting index zero, and a hash function (3x + 4)mod7. Assuming the hash table is initially empty, which of the following is the contents of the table when the sequence 1, 3, 8, 10 is inserted into the table using closed hashing? Note that '-' denotes an empty location in the table.
Answer: (B)
Hash function , with linear probing (try the next slot, wrapping around).
, so 1 goes to slot 0.
, so 3 goes to slot 6.
. Slot 0 is full, so 8 goes to slot 1.
. Slot 6 is full, so wrap around: slot 0 is full, slot 1 is full, slot 2 is free. 10 goes to slot 2.
Table: 1, 8, 10, -, -, -, 3. In (D), 10 and 8 are swapped, but 8 is inserted before 10, so 8 takes slot 1.
Answer: (B)
, so 1 goes to slot 0.
, so 3 goes to slot 6.
. Slot 0 is full, so 8 goes to slot 1.
. Slot 6 is full, so wrap around: slot 0 is full, slot 1 is full, slot 2 is free. 10 goes to slot 2.
Table: 1, 8, 10, -, -, -, 3. In (D), 10 and 8 are swapped, but 8 is inserted before 10, so 8 takes slot 1.
Answer: (B)
A hash table contains 10 buckets and uses linear probing to resolve collisions. The key values are integers and the hash function used is key % 10. If the values 43, 165, 62, 123, 142 are inserted in the table, in what location would the key value 142 be inserted?
Answer: (D)
goes to loc
goes to loc
goes to loc
goes to loc (collision, so next free space)
goes to loc (collision in , and are already full)
So the answer is D
Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the hash function x mod 10, which of the following statements are true?
i) 9679, 1989, 4199 hash to the same value
ii) 1471, 6171 has to the same value
iii) All elements hash to the same value
iv) Each element hashes to a different value
i) 9679, 1989, 4199 hash to the same value
ii) 1471, 6171 has to the same value
iii) All elements hash to the same value
iv) Each element hashes to a different value
Answer: (C)
The hash function gives the last digit of .
4322 2, 1334 4, 1471 1, 9679 9, 1989 9, 6171 1, 6173 3, 4199 9.
(i) 9679, 1989 and 4199 all hash to 9, so it is true.
(ii) 1471 and 6171 both hash to 1, so it is true.
(iii) False: 4322 hashes to 2 but 1334 hashes to 4.
(iv) False: 9679 and 1989 hash to the same value 9.
Only (i) and (ii) are true.
Answer: (C)
4322 2, 1334 4, 1471 1, 9679 9, 1989 9, 6171 1, 6173 3, 4199 9.
(i) 9679, 1989 and 4199 all hash to 9, so it is true.
(ii) 1471 and 6171 both hash to 1, so it is true.
(iii) False: 4322 hashes to 2 but 1334 hashes to 4.
(iv) False: 9679 and 1989 hash to the same value 9.
Only (i) and (ii) are true.
Answer: (C)
Keep practising