Hashing


Q1.

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)?
GateOverflow

Q2.

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 k be the number of keys, m be the number of slots in the hash table, and k \gt m. Which one of the following is the best hashing strategy to counteract the adversary?
GateOverflow

Q3.

Suppose we are given n keys, m hash table slots, and two simple uniform hash functions h_1 and h_2. Further suppose our hashing scheme uses h_1 for the odd keys and h_2 for the even keys. What is the expected number of keys in a slot?
GateOverflow

Q4.

Consider a double hashing scheme in which the primary hash function is h_1(k)=k\; mod \; 23, and the secondary hash function is h_2(k)=1+(k\; mod \; 19). 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_____________.
GateOverflow

Q5.

In linear hashing, if blocking factor bfr, loading factor i and file buckets N are known, the number of records will be
GateOverflow

Q6.

A Hash Function f defined as f(key)=keymod7. With linear probing while inserting the keys 37,38,72,48,98,11,56 into a table indexed from 0, in which location key 11 will be stored (Count table index 0 as 0^{th} location)?
GateOverflow

Q7.

A hash table with ten buckets with one slot per bucket is shown in the following figure. The symbols S1 to S7 initially entered using a hashing function with linear probing. The maximum number of comparisons needed in searching an item that is not present is
GateOverflow

Q8.

Given a hash table T with 25 slots that stores 2000 elements, the load factor \alpha for T is ____________.
GateOverflow

Q9.

A hash table with 10 buckets with one slot pet per bucket is depicted here. The symbols, S1 to S7 are initially entered using a hashing function with linear probing. The maximum number of comparisons needed in searching an item that is not present is:\begin{array}{|c|c|} \hline 0 & S 7 \\ \hline 1 & S 1 \\ \hline 2 & \\ \hline 3 & S 4 \\ \hline 4 & S 2 \\ \hline 5 & \\ \hline 6 & S 5 \\ \hline 7 & \\ \hline 8 & S 6 \\ \hline 9 & S 3 \\ \hline \end{array}
GateOverflow

Q10.

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?
GateOverflow