Q. How can hash tables be used in caching mechanisms?
-
A.
To store data in a linear fashion
-
B.
To quickly access frequently used data
-
C.
To sort data before retrieval
-
D.
To encrypt sensitive information
Solution
Hash tables can store frequently accessed data, allowing for quick retrieval and reducing the need to recompute or fetch data from slower storage.
Correct Answer:
B
— To quickly access frequently used data
Learn More →
Q. How do hash tables handle collisions?
-
A.
By using a linked list for each bucket
-
B.
By resizing the table
-
C.
By ignoring the new entry
-
D.
By using a binary search tree
Solution
One common method for handling collisions in hash tables is to use separate chaining, where each bucket contains a linked list of entries.
Correct Answer:
A
— By using a linked list for each bucket
Learn More →
Q. How do hash tables improve the performance of caching mechanisms?
-
A.
By using linked lists for storage
-
B.
By allowing quick access to cached data
-
C.
By sorting data before caching
-
D.
By using binary trees for organization
Solution
Hash tables provide quick access to cached data through direct indexing, significantly speeding up retrieval times.
Correct Answer:
B
— By allowing quick access to cached data
Learn More →
Q. In which scenario would you prefer a hash table over a binary search tree?
-
A.
When you need to maintain sorted order
-
B.
When you require frequent insertions and deletions
-
C.
When you need to perform range queries
-
D.
When you need constant time complexity for lookups
Solution
Hash tables provide average-case O(1) time complexity for lookups, making them preferable when quick access is needed.
Correct Answer:
D
— When you need constant time complexity for lookups
Learn More →
Q. What is a common application of hash tables in databases?
-
A.
Storing data in a sorted manner
-
B.
Fast data retrieval
-
C.
Data compression
-
D.
Data encryption
Solution
Hash tables allow for average-case constant time complexity O(1) for data retrieval, making them ideal for database indexing.
Correct Answer:
B
— Fast data retrieval
Learn More →
Q. What is a potential drawback of using hash tables?
-
A.
They require more memory than arrays
-
B.
They are slower than linked lists
-
C.
They cannot handle collisions
-
D.
They are not suitable for large datasets
Solution
Hash tables can require more memory due to the need for additional space to handle collisions and maintain performance.
Correct Answer:
A
— They require more memory than arrays
Learn More →
Q. What is the primary purpose of a hash function in a hash table?
-
A.
To sort the data
-
B.
To generate unique keys
-
C.
To map data to a fixed size
-
D.
To encrypt the data
Solution
A hash function maps data to a fixed size, allowing for efficient indexing in a hash table.
Correct Answer:
C
— To map data to a fixed size
Learn More →
Q. What is the time complexity of inserting an element into a hash table in the average case?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(1)
-
D.
O(n log n)
Solution
In the average case, inserting an element into a hash table has a time complexity of O(1) due to direct indexing.
Correct Answer:
C
— O(1)
Learn More →
Q. What is the time complexity of searching for an element in a hash table in the average case?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(1)
-
D.
O(n log n)
Solution
In the average case, searching for an element in a hash table has a time complexity of O(1) due to direct indexing.
Correct Answer:
C
— O(1)
Learn More →
Q. What is the time complexity of searching for an element in a well-designed hash table?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(1)
-
D.
O(n log n)
Solution
In a well-designed hash table, the average time complexity for searching is O(1), assuming a good hash function and low collision rate.
Correct Answer:
C
— O(1)
Learn More →
Q. Which application of hash tables is most suitable for implementing a phone book?
-
A.
Storing names in alphabetical order
-
B.
Quickly retrieving phone numbers by name
-
C.
Sorting phone numbers
-
D.
Finding the longest name
Solution
Hash tables allow for quick retrieval of phone numbers using names as keys, providing efficient access.
Correct Answer:
B
— Quickly retrieving phone numbers by name
Learn More →
Q. Which application would benefit most from using a hash table?
-
A.
Finding the shortest path in a graph
-
B.
Storing user sessions in a web application
-
C.
Sorting a list of numbers
-
D.
Performing binary search on a sorted array
Solution
Hash tables are ideal for storing user sessions due to their fast access times and ability to handle dynamic data.
Correct Answer:
B
— Storing user sessions in a web application
Learn More →
Q. Which of the following applications can benefit from hash tables?
-
A.
Implementing a stack
-
B.
Storing user sessions in web applications
-
C.
Performing depth-first search
-
D.
Sorting a list of numbers
Solution
Hash tables are commonly used to store user sessions in web applications for quick access and management of session data.
Correct Answer:
B
— Storing user sessions in web applications
Learn More →
Q. Which of the following hashing techniques can help reduce collisions?
-
A.
Chaining
-
B.
Linear probing
-
C.
Quadratic probing
-
D.
All of the above
Solution
All listed techniques (chaining, linear probing, and quadratic probing) are methods used to handle collisions in hash tables.
Correct Answer:
D
— All of the above
Learn More →
Q. Which of the following is a benefit of using hash tables for implementing sets?
-
A.
Maintaining order of elements
-
B.
Allowing duplicate elements
-
C.
Fast membership testing
-
D.
Using less memory than arrays
Solution
Hash tables provide average-case O(1) time complexity for membership testing, making them efficient for set operations.
Correct Answer:
C
— Fast membership testing
Learn More →
Q. Which of the following is a common method for implementing a hash function?
-
A.
Using a binary search
-
B.
Using a random number generator
-
C.
Using modular arithmetic
-
D.
Using a stack
Solution
Modular arithmetic is commonly used in hash functions to ensure that the hash value fits within the bounds of the array size.
Correct Answer:
C
— Using modular arithmetic
Learn More →
Q. Which of the following is NOT a benefit of using hash tables?
-
A.
Fast access time
-
B.
Dynamic resizing
-
C.
Ordered data storage
-
D.
Efficient memory usage
Solution
Hash tables do not maintain the order of elements, which is a characteristic of data structures like linked lists or trees.
Correct Answer:
C
— Ordered data storage
Learn More →
Q. Which of the following is NOT a typical use case for hash tables?
-
A.
Implementing a phone book
-
B.
Counting frequency of words in a document
-
C.
Storing a sorted list of items
-
D.
Implementing a set data structure
Solution
Hash tables are not designed for maintaining sorted order, which is required for a sorted list of items.
Correct Answer:
C
— Storing a sorted list of items
Learn More →
Showing 1 to 18 of 18 (1 Pages)