Coginzant Hash Table Questions & Answers

Question #1

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?

Hash Tables Questions AMCAT
Question Explanation

The sequence (A) doesn’t create the hash table as the element 52 appears before 23 in this sequence.

The sequence (B) doesn’t create the hash table as the element 33 appears before 46 in this sequence.

The sequence (C) creates the hash table as 42, 23 and 34 appear before 52 and 33, and 46 appears before 33.

The sequence (D) doesn’t create the hash table as the element 33 appears before 23 in this sequence.

Question #2

What is a hash function?
a)
Question Explanation

In a hash table, there are fewer array positions than the keys, so the position of the key in the array has to be computed, this is done using the hash function.

Question #3

What is the search complexity in direct addressing?
Question Explanation

Since every key has a unique array position, searching takes a constant time

Question #4

What is the best that can be the techniques to avoid collision?
Question Explanation

Making the hash function random is not really a good choice, although it is considered one of the techniques to avoid collisions along with chaining and simple uniform hashing.

Chaining is the best

Question #5

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?
Question Explanation

For each entry probability of collision is 1/20 {as possible total spaces =20, and an entry will go into only 1 place}
Say after inserting x values probability becomes ½
(1/20).x = ½
X=10

["0","40","60","80","100"]
["Need more practice! \n \n","Keep trying! \n \n","Not bad! \n \n","Good work! \n \n","Perfect! \n \n"]
Congratulations - you have completed Programming Hash Tables :A.

You scored 0 out of 5.

Your performance has been rated as

Prepare Better for Placement Papers