0% found this document useful (0 votes)
95 views

AMCAT Hash Tables Questions

A hash function computes the location of a key in an array. Search complexity in direct addressing is O(1) since every key has a unique array position. The best technique to avoid collisions is chaining, where keys that hash to the same location are stored in a linked list at that array index. A collision occurs when multiple elements are hashed to the same bucket. A hash table maps keys to values. Direct addressing uses an array with a distinct position for every possible key. Techniques to avoid collisions include making the hash function random, chaining, and uniform hashing. The load factor measures the average chain length. A doubly linked list is appropriate for simple chaining due to easier deletion. The probability of a collision in

Uploaded by

gsouvik4
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views

AMCAT Hash Tables Questions

A hash function computes the location of a key in an array. Search complexity in direct addressing is O(1) since every key has a unique array position. The best technique to avoid collisions is chaining, where keys that hash to the same location are stored in a linked list at that array index. A collision occurs when multiple elements are hashed to the same bucket. A hash table maps keys to values. Direct addressing uses an array with a distinct position for every possible key. Techniques to avoid collisions include making the hash function random, chaining, and uniform hashing. The load factor measures the average chain length. A doubly linked list is appropriate for simple chaining due to easier deletion. The probability of a collision in

Uploaded by

gsouvik4
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

AMCAT Hash Tables Questions

Question 1
What is a hash function? a)
A. A function has allocated memory to keys
B. A function that computes the location of the key in the array
C. A function that creates an array
D. None of the mentioned
Answer: Option B
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 2
What is the search complexity in direct addressing?
A. O(n)
B. O(logn)
C. O(nlogn)
D. O(1)
Answer: Option D
Explanation: Since every key has a unique array position, searching takes a constant time

Question 3
What is the best that can be the techniques to avoid collision?
A. Make the hash function appear random
B. Use the chaining method
C. Use uniform hashing
D. All of the mentioned
Answer: Option B
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 4
If several elements are competing for the same bucket in the hash table, what is it called?
A. Diffusion
B. Replication
C. Collision
D. None of the mentioned
Answer: Option C
Explanation: By definition

Question 5
What is a hash table?
A. A structure that maps values to keys
B. A structure that maps keys to values
C. A structure used for storage
D. A structure used to implement stack and queue
Answer: Option B
Explanation: A hash table is used to implement associative arrays which has a key-value pair,
so the hash table maps keys to values.

Question 6
What is direct addressing?
A. Distinct array position for every possible key
B. Fewer array positions than keys
C .Fewer keys than array positions
D. None of the mentioned
Answer: Option A
Explanation: Direct addressing is possible only when we can afford to allocate an array that
has one position for every possible key.

Question 7
What can be the techniques to avoid collision?
A. Make the hash function appear random
B. Use the chaining method
C. Use uniform hashing
D. All of the mentioned
Answer: Option D
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.

Question 8
What is the load factor?
A. Average array size
B. Average key size
C. Average chain length
D. None of the mentioned
Answer: Option C
Explanation: In simple chaining, load factor is the average number of elements stored in a
chain, and is given by the ratio of number of elements stored to the number of slots in the array.

Question 9
In simple chaining, what data structure is appropriate?
A. Singly linked list
B. Doubly linked list
C. Circular linked list
D. Binary trees
Answer: Option B
Explanation: Deletion becomes easier with doubly linked list, hence it is appropriate.

Question 10
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?
A. 40
B. 2
C. 5
D.10
Answer: Option D
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

You might also like