Hash Tables

Question 1
Marks : +2 | -2
Pass Ratio : 100%
What is a hash function?
A function has allocated memory to keys
A function that computes the location of the key in the array
A function that creates an array
A function that computes the location of the values in the array
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
Marks : +2 | -2
Pass Ratio : 100%
What is the search complexity in direct addressing?
O(n)
O(logn)
O(nlogn)
O(1)
Explanation:
Since every key has a unique array position, searching takes a constant time.
Question 3
Marks : +2 | -2
Pass Ratio : 100%
In simple chaining, what data structure is appropriate?
Singly linked list
Doubly linked list
Circular linked list
Binary trees
Explanation:
Deletion becomes easier with doubly linked list, hence it is appropriate.
Question 4
Marks : +2 | -2
Pass Ratio : 100%
What is a hash table?
A structure that maps values to keys
A structure that maps keys to values
A structure used for storage
A structure used to implement stack and queue
Explanation:
A hash table is used to implement associative arrays which has a key-value pair, so the has table maps keys to values.
Question 5
Marks : +2 | -2
Pass Ratio : 100%
What is the load factor?
Average array size
Average key size
Average chain length
Average hash table length
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 6
Marks : +2 | -2
Pass Ratio : 100%
If several elements are competing for the same bucket in the hash table, what is it called?
Diffusion
Replication
Collision
Duplication
Explanation:
In a hash table, if sevaral elements are computing for the same bucket then there will be a clash among elements. This condition is called Collision. The Collision is reduced by adding elements to a linked list and head address of linked list is placed in hash table.
Question 7
Marks : +2 | -2
Pass Ratio : 100%
In simple uniform hashing, what is the search complexity?
O(n)
O(logn)
O(nlogn)
O(1)
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.
Question 8
Marks : +2 | -2
Pass Ratio : 100%
What is simple uniform hashing?
Every element has equal probability of hashing into any of the slots
A weighted probabilistic method is used to hash elements into the slots
Elements has Random probability of hashing into array slots
Elements are hashed based on priority
Explanation:
In simple uniform hashing, any given element is equally likely to hash into any of the slots available in the array.
Question 9
Marks : +2 | -2
Pass Ratio : 100%
What is direct addressing?
Distinct array position for every possible key
Fewer array positions than keys
Fewer keys than array positions
Same array position for all keys
Explanation:
Direct addressing is possible only when we can afford to allocate an array that has one position for every possible key.
Question 10
Marks : +2 | -2
Pass Ratio : 100%
Which of the following is not a technique to avoid a collision?
Make the hash function appear random
Use the chaining method
Use uniform hashing
Increasing hash table size
Explanation:
On increasing hash table size, space complexity will increase as we need to reallocate the memory size of hash table for every collision. It is not the best technique to avoid a collision. We can avoid collision by making hash function random, chaining method and uniform hashing.