MCQ - Hashing Function in Data Structure
11. 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
View Answer
Ans : A
Explanation: Direct addressing is possible only when we can afford to allocate an array that has one position for every possible key.
12. What is the search complexity in direct addressing?
A. O(n)
B. O(logn)
C. O(nlogn)
D. O(1)
View Answer
Ans : D
Explanation: Since every key has a unique array position, searching takes a constant time.
13. What is a hash function?
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
View Answer
Ans : 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.
14. 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
View Answer
Ans : 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.
15. What is simple uniform hashing?
A. Every element has equal probability of hashing into any of the slots
B. A weighted probabilistic method is used to hash elements into the slots
C. All of the mentioned
D. None of the mentioned
View Answer
Ans : A
Explanation: In simple uniform hashing, any given element is equally likely to hash into any of the slots available in the array.
16. In simple uniform hashing, what is the search complexity?
A. O(n)
B. O(logn)
C. O(nlogn)
D. O(1)
View Answer
Ans : 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.
17. 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
Ans : B
Explanation: Deletion becomes easier with doubly linked list, hence it is appropriate.
18.Which of these are core interfaces in the collection framework. Select the one correct answer.
A. Tree
B. Stack
C. Queue
D. Map
E. LinkedList
View Answer
19. Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the hash function x mod 10, which of the following statements are true?
i. 9679, 1989, 4199 hash to the same value
ii. 1471, 6171 hash to the same value
iii. All elements hash to the same value
iv. Each element hashes to a different value
A. i only
B. ii only
C. i and ii only
D. iii or iv
View Answer
Ans : C
Hash function given is mod(10).
9679, 1989 and 4199 all these give same hash value i.e 9
1471 and 6171 give hash value 1
Also Check :
Discussion