Q. In a hash table, what is the effect of a poor hash function?
A.
Increased memory usage
B.
Faster access times
C.
Higher collision rates
D.
Simpler implementation
Show solution
Solution
A poor hash function can lead to higher collision rates, which degrades the performance of the hash table.
Correct Answer:
C
— Higher collision rates
Learn More →
Q. In a hash table, what is the purpose of a hash function?
A.
To sort the data
B.
To convert keys into indices
C.
To store data in a linked list
D.
To manage memory allocation
Show solution
Solution
The hash function converts keys into indices, allowing for efficient data retrieval in the hash table.
Correct Answer:
B
— To convert keys into indices
Learn More →
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. In a max-heap, if the root node has a value of 20, what can be the maximum value of its children?
Show solution
Solution
In a max-heap, the value of a parent node must be greater than or equal to its children, so the maximum value of the children can be 20.
Correct Answer:
C
— 20
Learn More →
Q. In a max-heap, what is the relationship between the height of the heap and the number of elements?
A.
Height is log(n)
B.
Height is n
C.
Height is n log(n)
D.
Height is constant
Show solution
Solution
The height of a max-heap is log(n) because it is a complete binary tree, where n is the number of elements.
Correct Answer:
A
— Height is log(n)
Learn More →
Q. In a max-heap, which of the following is true about the parent and child nodes?
A.
Parent is always greater than children
B.
Parent is always less than children
C.
Parent can be equal to children
D.
None of the above
Show solution
Solution
In a max-heap, the parent node is always greater than or equal to its child nodes.
Correct Answer:
A
— Parent is always greater than children
Learn More →
Q. In a max-heap, which of the following is true about the root node?
A.
It is the smallest element
B.
It is the largest element
C.
It can be any element
D.
It is the second largest element
Show solution
Solution
In a max-heap, the root node is always the largest element, as the heap property ensures that each parent node is greater than or equal to its children.
Correct Answer:
B
— It is the largest element
Learn More →
Q. In a max-heap, which of the following statements is true?
A.
The parent is always less than the children
B.
The parent is always greater than the children
C.
The children can be greater than the parent
D.
All elements are in sorted order
Show solution
Solution
In a max-heap, the parent node is always greater than or equal to its children, maintaining the max-heap property.
Correct Answer:
B
— The parent is always greater than the children
Learn More →
Q. In a max-heap, which property must be maintained?
A.
The parent node is always less than its children
B.
The parent node is always equal to its children
C.
The parent node is always greater than or equal to its children
D.
The children nodes are always greater than their parent
Show solution
Solution
In a max-heap, each parent node must be greater than or equal to its children to maintain the heap property.
Correct Answer:
C
— The parent node is always greater than or equal to its children
Learn More →
Q. In a min-heap, which of the following is true about the parent and child nodes?
A.
Parent is always greater than children
B.
Parent is always less than children
C.
Parent can be equal to children
D.
None of the above
Show solution
Solution
In a min-heap, the parent node is always less than or equal to its children, ensuring the minimum element is at the root.
Correct Answer:
B
— Parent is always less than children
Learn More →
Q. In a min-heap, which of the following is true?
A.
The root is the smallest element
B.
The root is the largest element
C.
All parent nodes are smaller than their children
D.
Both A and C
Show solution
Solution
In a min-heap, the root is the smallest element, and all parent nodes are smaller than their children.
Correct Answer:
D
— Both A and C
Learn More →
Q. In a min-heap, which of the following statements is true?
A.
The parent node is always greater than its children
B.
The parent node is always less than its children
C.
All nodes are in sorted order
D.
The smallest element is at the bottom
Show solution
Solution
In a min-heap, the parent node is always less than or equal to its children, ensuring that the smallest element is at the root.
Correct Answer:
B
— The parent node is always less than its children
Learn More →
Q. In a priority queue implemented with a binary heap, what happens when the heap property is violated?
A.
The heap is automatically sorted
B.
The heap is restructured
C.
Elements are removed
D.
No action is taken
Show solution
Solution
When the heap property is violated, the heap is restructured to restore the property, typically through a process called 'heapify'.
Correct Answer:
B
— The heap is restructured
Learn More →
Q. In a priority queue implemented with a binary heap, what happens when the maximum element is removed?
A.
The last element is placed at the root
B.
The root is replaced with the minimum element
C.
The heap is restructured
D.
Both A and C
Show solution
Solution
When the maximum element is removed, the last element is placed at the root, and then the heap is restructured to maintain the heap property.
Correct Answer:
D
— Both A and C
Learn More →
Q. In a priority queue, how is the priority of elements typically determined?
A.
By their insertion order
B.
By their value
C.
By a custom comparator function
D.
By their index in the array
Show solution
Solution
The priority of elements in a priority queue can be determined by a custom comparator function that defines how priorities are assigned.
Correct Answer:
C
— By a custom comparator function
Learn More →
Q. In Dijkstra's algorithm, what role does a priority queue play?
A.
To store all vertices
B.
To keep track of visited nodes
C.
To select the next vertex with the smallest distance
D.
To sort the edges
Show solution
Solution
Dijkstra's algorithm uses a priority queue to efficiently select the next vertex with the smallest distance from the source.
Correct Answer:
C
— To select the next vertex with the smallest distance
Learn More →
Q. In graph theory, what does a cycle mean?
A.
A path that visits every vertex
B.
A path that starts and ends at the same vertex
C.
A path with no edges
D.
A disconnected graph
Show solution
Solution
A cycle in a graph is defined as a path that starts and ends at the same vertex without repeating any edges.
Correct Answer:
B
— A path that starts and ends at the same vertex
Learn More →
Q. In the context of Disjoint Set Union, what does the 'Union by Rank' optimization do?
A.
It merges two sets based on their size
B.
It keeps track of the height of trees to minimize depth
C.
It sorts the elements in each set
D.
It finds the maximum element in a set
Show solution
Solution
The 'Union by Rank' optimization keeps track of the height of trees to minimize depth, ensuring that the smaller tree is always added under the root of the larger tree.
Correct Answer:
B
— It keeps track of the height of trees to minimize depth
Learn More →
Q. In the context of Disjoint Set Union, what does the 'Union by Rank' technique do?
A.
It merges two sets based on their size
B.
It merges two sets based on their depth
C.
It keeps track of the number of elements in each set
D.
It optimizes the 'Find' operation
Show solution
Solution
The 'Union by Rank' technique merges two sets based on their depth, ensuring that the smaller tree is always added under the root of the larger tree to keep the overall tree shallow.
Correct Answer:
B
— It merges two sets based on their depth
Learn More →
Q. In the context of Disjoint Set Union, what does the 'Union' operation do?
A.
Combines two sets into one
B.
Finds the maximum element in a set
C.
Removes an element from a set
D.
Sorts the elements in a set
Show solution
Solution
The 'Union' operation combines two sets into one in the Disjoint Set Union data structure.
Correct Answer:
A
— Combines two sets into one
Learn More →
Q. In the context of Disjoint Set Union, what does the term 'union by rank' refer to?
A.
Combining two sets based on their size
B.
Combining two sets based on their depth
C.
Finding the maximum element in a set
D.
Sorting elements in a set
Show solution
Solution
Union by rank refers to the strategy of combining two sets by attaching the smaller tree under the root of the larger tree, thus keeping the overall tree shallow.
Correct Answer:
B
— Combining two sets based on their depth
Learn More →
Q. In which scenario is the Disjoint Set Union most commonly used?
A.
Finding the shortest path in a graph
B.
Detecting cycles in a graph
C.
Sorting an array
D.
Searching for an element in a list
Show solution
Solution
The Disjoint Set Union is commonly used for detecting cycles in a graph, particularly in algorithms like Kruskal's for finding the minimum spanning tree.
Correct Answer:
B
— Detecting cycles in a graph
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
Show solution
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 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 application of a priority queue?
A.
Implementing a stack
B.
Managing tasks in a scheduling system
C.
Sorting an array
D.
Searching for an element in a list
Show solution
Solution
Priority queues are often used in scheduling systems to manage tasks based on their priority.
Correct Answer:
B
— Managing tasks in a scheduling system
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
Show solution
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 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 a hash table?
A.
It requires more memory than arrays
B.
It is slower than binary search trees
C.
It cannot handle dynamic data
D.
It is not suitable for large datasets
Show solution
Solution
Hash tables can require more memory than arrays due to the need for additional space to handle collisions and maintain performance.
Correct Answer:
A
— It requires more memory than arrays
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
Show solution
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 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 →
Showing 31 to 60 of 179 (6 Pages)