Hashing MCQ
Hashing MCQ
Q.1) A hash table with 100 buckes with one slot per bucket is depicted . The symbols, Sl
to S7 are initially entered using a hashing fucntion with linear probing. The maxmmum
number of comparisons needed in searching an intem that is not present is
A. 4
B. 5
C. 6
m
D. 3
ANSWER : 5
co
SOLUTION :
It will be one more than the size of the biggest cluster (which is 4) in this case. This is
because, assume a search key hashing onto bin 8. By liner probing the next location for
searching is bin 9. Then 0, then 1. if all these resulted in a miss, we try at bin 2 and stop
as it is vacant. This logic may not work if deletion operation is done before the search.
e.
Q.2) If h is any hashing function and is used to hash n keys in to a table of size m,
in
where n<=m, the expected number of collisions involving a particular key x is :
A. less than 1.
B. less than n. nl
C. less than m.
D. less than n/2.
tio
ANSWER : less than 1.
SOLUTION :
Theorem: If h is chosen from a universal class of hash functions and is used to hash n
keys into a table of size m, where n <= m, the expected number of collisions involving a
p
Q.3) Which of the following has a desired key is searched, starting itself from hash
address, sequentially in a table?
w
A. Quadratic probing
B. Random probing
C. Reverse probing(d) Chaining
w
D. Linear probing.
SOLUTION :
Linear Probing has a desired key is searched, starting itself from hash address,
sequentially in a table.
A. When collision happens, we create a new memory location outside of the existing
table, and use a chain to link to the new memory location
B. When collision happens, we enlarge the hash table
C. When collision happens, we look for an unoccupied memory location in the existing
table
D. We use an extra table to collect all collided data
ANSWER : When collision happens, we look for an unoccupied memory location in the
existing table
SOLUTION :
The meaning of the open addressing itself is to look and probe for unoccupied and open
location to place the incoming key.
A. Binary Search
B. Linear Search
Page 1
Questions and Answers
C. Tree Search
D. Hashing
ANSWER : Hashing
SOLUTION :
A technique for direct search is Hashing. Hash tables are efficient when it comes to
random access. Unlike in lists, where we do not know ahead of time where we will ?nd a
m
value, the hash function points to the bin where the value is expected to be.
Q.6) The technique of linear probing for collision resolution can lead to
co
A. The technique of linear probing for collision resolution can lead to
B. Radix ordering
e.
C. Overflow
D. Clustering
in
ANSWER : Clustering
SOLUTION :
Because, if we follow the linear probing method to resolve the collision then it may lead
to the clustering. nl
Q.7) Folding is a method of generating
tio
A. A hash function
B. Index function for a triangular matrix
C. Linking the tail node to the head node in linked list
D. Linear probing
p
SOLUTION :
Folding is one of the methods in hashing functions. It can be shift folding or rounded
folding.
w
Q.8) A hash function randomly distributes records one by one in a space that can hold x
number of records. The probability that the mth record is the first record to result in
w
collision is
A. (x-1) (x-2)...(x-(m-2))(m-1)/xm-1
w
B. (x-1) (x-2)...(x-(m-1))(m-1)/xm-1
C. (x-1) (x-2)...(x-(m-2))(m-1)/xm
D. (x-1) (x-2)...(x-(m-1))(m-1)/xm
A. A hash function produces the same address for two different keys: h( key1 ) =
h( key2 ) where key1 == key2
B. Two different hash functions produce the same address for a given key: h1(
key ) = h2( key )
C. Two different hash functions produce the same address for two different keys:
h1( key1 ) = h2( key2 ) where key1 == key2
Page 2
Questions and Answers
D. A hash function produces the same address for two different keys with different
lengths: h( key1 ) = h( key2 ) where length(key1) == length (key2)
ANSWER : A hash function produces the same address for two different keys:
h( key1 ) = h( key2 ) where key1 == key2
SOLUTION :
Collision happens if the hash function produces the same address for two different keys
m
in the prime area.
Q.10) The average search time of hashing, with linear probing will be less if the load
co
factor
e.
C. is far greater than one
D. none of the above
in
ANSWER : is far less than one
SOLUTION :
Load factor is the ration of number of records that are currently present and the total
number of records that can be present. If the load factor is less, free space will be more.
nl
This means probability of collision is less. So, the search time will be less.
tio
Q.11) A hasn funciton f defined as f (key) = key mod 7, with linear probibng, us used to
insert the keys 37, 38, 72, 48, 98, 11, 56 into a table indexed from 0 to 6. What will be
the location of key 11?
A. 3
p
B. 4
C. 5
.a
D. 6
ANSWER : 5
w
SOLUTION :
f(37) = 37 mod 7 =2. So, 37 will be put in location
2. f(38) = (3. So, 38 will be in third location.
w
f(72) =2. This results in a collision. With linear probing as the collison resolving strategy,
the alternate location for 72 will be the location 4 (i.e. next vacant slot in the current
configuration). Continuing this way, the final configuration will be 98, 56, 37, 38, 72, 11,
w
48.
Q.12) A hash table can store a maximumof 10 rdcords. Currently there are records in
locations 1, 3, 4, 7, 8, 9, 10. The probability of a new record going ono location 2, with a
hash function resolving collisions by linear probing is
A. 0.6
B. 0.1
C. 0.2
D. 0.5
ANSWER : 0.6
SOLUTION :
If the new record hashes onto one of the six locations 7, 8, 9, 10, 1 or 2, the location 2
will receive the new record. The probability is 6/10 (as 10 is the total possible number of
locations).
Page 3