Q. In a hash table, what is the purpose of the hash function?
A.
To sort the data
B.
To convert keys into hash codes
C.
To store data in a binary tree
D.
To manage memory allocation
Show solution
Solution
The hash function converts keys into hash codes, which are then used to determine the index in the hash table where the corresponding value is stored.
Correct Answer:
B
— To convert keys into hash codes
Learn More →
Q. What happens when the load factor of a hash table exceeds a certain threshold?
A.
The table is resized
B.
The table is deleted
C.
The table becomes immutable
D.
The table's performance improves
Show solution
Solution
When the load factor exceeds a certain threshold, the hash table is typically resized to maintain efficient access times.
Correct Answer:
A
— The table is resized
Learn More →
Q. What is a common strategy for resizing a hash table?
A.
Doubling the size
B.
Halving the size
C.
Increasing by a fixed amount
D.
Randomly changing the size
Show solution
Solution
A common strategy for resizing a hash table is to double its size when the load factor exceeds a certain threshold to maintain performance.
Correct Answer:
A
— Doubling the size
Learn More →
Q. What is a potential drawback of using open addressing for collision resolution?
A.
Increased memory usage
B.
Higher time complexity for insertions
C.
Requires a linked list
D.
Cannot handle deletions
Show solution
Solution
A potential drawback of using open addressing for collision resolution is that it can lead to higher time complexity for insertions as the table fills up.
Correct Answer:
B
— Higher time complexity for insertions
Learn More →
Q. What is the effect of a poor hash function on a hash table?
A.
Increased speed of operations
B.
More collisions and decreased performance
C.
Better memory utilization
D.
No effect on performance
Show solution
Solution
A poor hash function can lead to more collisions, which decreases the performance of the hash table due to longer search times.
Correct Answer:
B
— More collisions and decreased performance
Learn More →
Q. What is the result of a poor hash function?
A.
Increased memory usage
B.
Faster access times
C.
More collisions
D.
Better data organization
Show solution
Solution
A poor hash function can lead to more collisions, which degrades the performance of the hash table and increases the time complexity for operations.
Correct Answer:
C
— More collisions
Learn More →
Q. What is the time complexity of searching for an element in a hash table on average?
A.
O(n)
B.
O(log n)
C.
O(1)
D.
O(n^2)
Show solution
Solution
On average, searching for an element in a hash table has a time complexity of O(1) due to direct access via the hash function.
Correct Answer:
C
— O(1)
Learn More →
Q. What is the worst-case time complexity for searching in a hash table with chaining?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
In the worst case, if all keys hash to the same index, searching in a hash table with chaining can take O(n) time.
Correct Answer:
C
— O(n)
Learn More →
Q. Which of the following is a common method for handling collisions in hash tables?
A.
Chaining
B.
Sorting
C.
Binary Search
D.
Recursion
Show solution
Solution
Chaining is a common collision resolution technique where each slot in the hash table points to a linked list of entries that hash to the same index.
Correct Answer:
A
— Chaining
Learn More →
Q. Which of the following is a disadvantage of using hash tables?
A.
Fast access time
B.
Dynamic resizing
C.
Collision handling complexity
D.
Easy implementation
Show solution
Solution
One disadvantage of hash tables is the complexity involved in handling collisions, which can affect performance and implementation.
Correct Answer:
C
— Collision handling complexity
Learn More →
Q. Which of the following is NOT a characteristic of a good hash function?
A.
Deterministic
B.
Uniform distribution
C.
Fast computation
D.
Produces a sorted output
Show solution
Solution
A good hash function should be deterministic, provide a uniform distribution of hash values, and be fast to compute, but it does not need to produce a sorted output.
Correct Answer:
D
— Produces a sorted output
Learn More →
Q. Which of the following scenarios would benefit most from using a hash table?
A.
When data needs to be stored in a sorted order
B.
When frequent insertions and deletions are required
C.
When searching for elements by key is common
D.
When data is accessed sequentially
Show solution
Solution
Hash tables are particularly beneficial when searching for elements by key is common, as they provide average O(1) time complexity for lookups.
Correct Answer:
C
— When searching for elements by key is common
Learn More →
Q. Which of the following scenarios would most likely benefit from using a hash table?
A.
Storing a sorted list of numbers
B.
Implementing a priority queue
C.
Counting the frequency of words in a document
D.
Performing a binary search
Show solution
Solution
A hash table is particularly useful for counting the frequency of words in a document, as it allows for quick updates and lookups.
Correct Answer:
C
— Counting the frequency of words in a document
Learn More →
Q. Which of the following statements about open addressing is true?
A.
It uses linked lists to handle collisions
B.
It requires more memory than chaining
C.
It probes for the next available slot in the table
D.
It is slower than chaining
Show solution
Solution
Open addressing resolves collisions by probing for the next available slot in the hash table, rather than using linked lists.
Correct Answer:
C
— It probes for the next available slot in the table
Learn More →
Showing 1 to 14 of 14 (1 Pages)