Data Structure Questions and Answers
Data Structure Questions and Answers
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Hash
Tables”.
Answer: c
Explanation: None.
Answer: a
Explanation: Direct addressing is possible only when we can afford to allocate an array that has
one position for every possible key.
4. What is the search complexity in direct addressing?
a) O(n)
b) O(logn)
c) O(nlogn)
d) O(1)
View Answer
Answer: d
Explanation: Since every key has a unique array position, searching takes a constant time.
Answer: 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.
Answer: 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.
7. What is the load factor?
a) Average array size
b) Average key size
c) Average chain length
d) None of the mentioned
View Answer
Answer: 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.
Answer: a
Explanation: In simple uniform hashing, any given element is equally likely to hash into any of the
slots available in the array.
Answer: d
Explanation: There are two cases, once when the search is successful and when it is
unsuccessful, but in both the cases, the complexity is O(1+alpha) where 1 is to compute the
hash function and alpha is the load factor.
10. In simple chaining, what data structure is appropriate?
a) Singly linked list
b) Doubly linked list
c) Circular linked list
d) Binary trees
View Answer
Answer: b
Explanation: Deletion becomes easier with doubly linked list, hence it is appropriate.