/* */ Click to Join Live Class with Shankar sir Call 9798158723

Data Structure MCQ - Hashing


Q1. What is direct addressing?
  1. Distinct array position for every possible key
  2. Fewer array positions than keys
  3. Fewer keys than array positions
  4. Same array position for all keys

Answer:- (A).
Explanations :Direct addressing is possible only when we can afford to allocate an array that has one position for every possible key.
Q2.What is a hash function?
  1. A function has allocated memory to keys
  2. A function that computes the location of the key in the array
  3. A function that creates an array
  4. A function that computes the location of the values in the array

Answer:- (B).
Explanations :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.
Q3. What is simple uniform hashing?
  1. Every element has equal probability of hashing into any of the slots
  2. A weighted probabilistic method is used to hash elements into the slots
  3. Elements has Random probability of hashing into array slots
  4. Elements are hashed based on priority

Answer:- (A).
Explanations :In simple uniform hashing, any given element is equally likely to hash into any of the slots available in the array.
Q4.In simple chaining, what data structure is appropriate?
  1. Singly linked list
  2. Doubly linked list
  3. Circular linked list
  4. Binary trees

Answer:- (B).
Explanations :Deletion becomes easier with doubly linked list, hence it is appropriate.
Q5.What is the search complexity in direct addressing?
  1. O(n)
  2. O(logn)
  3. O(nlogn)
  4. O(1)

Answer:- (D).
Explanations :Since every key has a unique array position, searching takes a constant time.
Q6.What is a hash function?
  1. A function has allocated memory to keys
  2. A function that computes the location of the key in the array
  3. A function that creates an array
  4. None of the mentioned

Answer:- (B).
Explanations : 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.
Q7.What is simple uniform hashing?
  1. Every element has equal probability of hashing into any of the slots
  2. A weighted probabilistic method is used to hash elements into the slots
  3. Elements has Random probability of hashing into array slots
  4. Elements are hashed based on priority

Answer:- (A).
Explanations :In simple uniform hashing, any given element is equally likely to hash into any of the slots available in the array.
Q8.In simple uniform hashing, what is the search complexity?
  1. O(n)
  2. O(logn)
  3. O(nlogn)
  4. O(1)

Answer:- (d).
Explanations :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.
Q9.What is the advantage of the hash table over a linked list?
  1. faster access of data
  2. easy to implement
  3. very efficient for less number of entries
  4. exhibit good locality of reference

Answer:- (A).
Explanations : Clarification: Hash table is a data structure that has an advantage that it allows fast access of elements. But linked list is easier to implement as compared to the hash table.
Q10 Which of the following trait of a hash function is most desirable?
  1. it should cause less collisions
  2. it should cause more collisions
  3. it should occupy less space
  4. it should be easy to implement

Answer:- (a).
Explanations : Clarification: Hash function calculates and returns the index for corresponding data. So the most important trait of a hash function is that it should cause a minimum number of collisions.