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 1–5 of 19
Consider a hash table that is initially empty. The hash table is maintained using open addressing with linear probing. The hash function used is .
Consider the following sequence of insertions performed on :
Which of the following positions in the hash table is/are empty after these insertions are performed?
Consider the following sequence of insertions performed on :
Which of the following positions in the hash table is/are empty after these insertions are performed?
One or more options are correct.
Answer: (C)
The hash function is . The table size is , with indices from to . Collisions use linear probing.
Find the hash of each key. If the slot is taken, move to the next slot, wrapping around the table:
The table at the end: . The empty positions are .
Among the given choices (0, 10, 2, 1), only position 2 is empty. Positions 0, 1 and 10 are all filled.
Answer: Position 2
Find the hash of each key. If the slot is taken, move to the next slot, wrapping around the table:
The table at the end: . The empty positions are .
Among the given choices (0, 10, 2, 1), only position 2 is empty. Positions 0, 1 and 10 are all filled.
Answer: Position 2
The keys are inserted into a hash table using the hash function . The collisions are resolved by chaining. After all the keys are inserted, the length of the longest chain is ________. (answer in integer)
Answer: 3
First find for every key. Then put the keys with the same value into one chain:
The chains are: bucket has (length ); bucket has (length ); bucket has (length ); bucket has (length ); bucket has (length ).
The longest chain is of length . It is in bucket and holds .
Answer: 3
The chains are: bucket has (length ); bucket has (length ); bucket has (length ); bucket has (length ); bucket has (length ).
The longest chain is of length . It is in bucket and holds .
Answer: 3
In a double hashing scheme, and are the auxiliary hash functions. The size of the hash table is 11. The hash function for the -th probe in the open address table is The following keys are inserted in the given order: 63, 50, 25, 79, 67, 24.
The slot at which key 24 gets stored is _________. (Answer in integer)
The slot at which key 24 gets stored is _________. (Answer in integer)
Answer: 10 to 11
Double hashing uses and . For probe the slot is , and the table size is .
Insert the keys in order. On a collision, probe again.
: , so slot (empty).
: , so slot (empty).
: , so slot (empty).
: , so slot (empty).
: , so slot (empty).
: is taken by , and . Probe : is taken by . Probe : is empty, so it goes in slot .
The official key accepts 10 to 11 (11 would be the same slot counted from 1 instead of 0).
Answer: 10
Insert the keys in order. On a collision, probe again.
: , so slot (empty).
: , so slot (empty).
: , so slot (empty).
: , so slot (empty).
: , so slot (empty).
: is taken by , and . Probe : is taken by . Probe : is empty, so it goes in slot .
The official key accepts 10 to 11 (11 would be the same slot counted from 1 instead of 0).
Answer: 10
An algorithm has to store several keys generated by an adversary in a hash table. The adversary is malicious who tries to maximize the number of collisions. Let be the number of keys, be the number of slots in the hash table, and .
Which one of the following is the best hashing strategy to counteract the adversary?
Which one of the following is the best hashing strategy to counteract the adversary?
Answer: (C)
The adversary knows any fixed hash function, whether it is the division method or the multiplication method. So the adversary can choose keys that all collide.
Universal hashing chooses the hash function at random from a family of functions while the program runs. The adversary cannot predict which function will be used, so the expected number of collisions stays small.
Answer: Universal hashing method
Universal hashing chooses the hash function at random from a family of functions while the program runs. The adversary cannot predict which function will be used, so the expected number of collisions stays small.
Answer: Universal hashing method
Suppose we are given keys, hash table slots, and two simple uniform hash functions and . Further suppose our hashing scheme uses for the odd keys and for the even keys. What is the expected number of keys in a slot?
Answer: (B)
and are both simple uniform hash functions. So each key, odd or even, goes to a given slot with probability .
The expected number of keys in a slot . It does not matter which hash function is used.
Answer:
The expected number of keys in a slot . It does not matter which hash function is used.
Answer:
Keep practising