Q. What is a potential issue with using a poor hash function?
A.
Increased memory usage
B.
Faster access times
C.
Higher collision rates
D.
Easier debugging
Show solution
Solution
A poor hash function can lead to higher collision rates, which degrades the performance of the hash table and increases the time complexity for operations.
Correct Answer:
C
— Higher collision rates
Learn More →
Q. What is the 'union by rank' optimization in Disjoint Set Union?
A.
Always attaching the smaller tree under the larger tree
B.
Always attaching the larger tree under the smaller tree
C.
Randomly attaching trees
D.
Merging trees based on their height
Show solution
Solution
'Union by rank' optimization involves always attaching the smaller tree under the larger tree to keep the overall tree height minimized.
Correct Answer:
A
— Always attaching the smaller tree under the larger tree
Learn More →
Q. What is the average time complexity for searching an element in a hash table?
A.
O(n)
B.
O(log n)
C.
O(1)
D.
O(n^2)
Show solution
Solution
The average time complexity for searching an element in a hash table is O(1) due to the direct access provided by the hash function.
Correct Answer:
C
— O(1)
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 ideal load factor for a hash table to maintain efficient performance?
A.
0.1
B.
0.5
C.
1.0
D.
2.0
Show solution
Solution
An ideal load factor is typically around 0.5, balancing space and time efficiency while minimizing collisions.
Correct Answer:
B
— 0.5
Learn More →
Q. What is the initial state of a Disjoint Set Union when n elements are added?
A.
All elements are in a single set
B.
All elements are in separate sets
C.
All elements are sorted
D.
All elements are merged
Show solution
Solution
When n elements are added to a Disjoint Set Union, the initial state is that all elements are in separate sets.
Correct Answer:
B
— All elements are in separate sets
Learn More →
Q. What is the initial state of each element in a Disjoint Set Union when it is first created?
A.
Each element is its own set
B.
All elements are in a single set
C.
Elements are sorted
D.
Elements are in random sets
Show solution
Solution
When first created, each element in a Disjoint Set Union is its own set, meaning they are all disjoint.
Correct Answer:
A
— Each element is its own set
Learn More →
Q. What is the main advantage of using path compression in Disjoint Set Union?
A.
It reduces the number of elements in a set
B.
It speeds up the union operation
C.
It flattens the structure of the tree for faster future queries
D.
It allows for duplicate elements
Show solution
Solution
The main advantage of using path compression is that it flattens the structure of the tree, leading to faster future queries by reducing the depth of the trees.
Correct Answer:
C
— It flattens the structure of the tree for faster future queries
Learn More →
Q. What is the main advantage of using path compression in the 'Find' operation?
A.
It increases the size of the data structure
B.
It reduces the time complexity of future operations
C.
It makes the data structure more complex
D.
It allows for multiple unions at once
Show solution
Solution
The main advantage of using path compression in the 'Find' operation is that it reduces the time complexity of future operations by flattening the structure of the tree.
Correct Answer:
B
— It reduces the time complexity of future operations
Learn More →
Q. What is the main advantage of using union by rank in Disjoint Set Union?
A.
It increases the size of the sets
B.
It minimizes the height of the trees
C.
It allows for faster sorting
D.
It simplifies the code
Show solution
Solution
The main advantage of using union by rank is that it minimizes the height of the trees, leading to more efficient 'Find' operations.
Correct Answer:
B
— It minimizes the height of the trees
Learn More →
Q. What is the main disadvantage of using open addressing for collision resolution?
A.
It requires more memory
B.
It can lead to clustering
C.
It is slower than chaining
D.
It cannot handle deletions
Show solution
Solution
Open addressing can lead to clustering, where a group of consecutive slots are filled, which can degrade performance during searches and insertions.
Correct Answer:
B
— It can lead to clustering
Learn More →
Q. What is the maximum height of a binary heap with n elements?
A.
n
B.
log n
C.
n log n
D.
2n
Show solution
Solution
The maximum height of a binary heap is log n, as it is a complete binary tree.
Correct Answer:
B
— log n
Learn More →
Q. What is the maximum number of elements in a binary heap of height h?
A.
2^h
B.
2^(h+1) - 1
C.
h + 1
D.
h^2
Show solution
Solution
The maximum number of elements in a binary heap of height h is 2^(h+1) - 1, as it is a complete binary tree.
Correct Answer:
B
— 2^(h+1) - 1
Learn More →
Q. What is the primary advantage of using a binary heap over an unsorted array for implementing a priority queue?
A.
Faster insertion
B.
Faster deletion
C.
Better memory usage
D.
Easier implementation
Show solution
Solution
A binary heap allows for faster deletion of the maximum (or minimum) element compared to an unsorted array, where deletion would take O(n) time.
Correct Answer:
B
— Faster deletion
Learn More →
Q. What is the primary advantage of using a Fibonacci heap over a binary heap?
A.
Faster insertion time
B.
Lower memory usage
C.
Faster decrease-key operation
D.
Easier implementation
Show solution
Solution
Fibonacci heaps provide a faster decrease-key operation, which is beneficial in algorithms like Dijkstra's.
Correct Answer:
C
— Faster decrease-key operation
Learn More →
Q. What is the primary advantage of using a priority queue over a regular queue?
A.
Faster access to elements
B.
Elements are processed in the order of their priority
C.
Lower memory usage
D.
Easier implementation
Show solution
Solution
The primary advantage of a priority queue is that elements are processed based on their priority rather than their order of arrival.
Correct Answer:
B
— Elements are processed in the order of their priority
Learn More →
Q. What is the primary difference between a binary heap and a binary search tree?
A.
Binary heaps are complete binary trees, while binary search trees are not
B.
Binary heaps allow duplicate elements, while binary search trees do not
C.
Binary heaps are used for priority queues, while binary search trees are used for searching
D.
All of the above
Show solution
Solution
The primary differences include that binary heaps are complete binary trees used for priority queues, while binary search trees are not necessarily complete and are used for searching.
Correct Answer:
D
— All of the above
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
Show solution
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 primary purpose of the Disjoint Set Union (Union Find) data structure?
A.
To sort elements efficiently
B.
To find the shortest path in a graph
C.
To manage a collection of disjoint sets
D.
To implement a stack
Show solution
Solution
The primary purpose of the Disjoint Set Union (Union Find) data structure is to manage a collection of disjoint sets, allowing for efficient union and find operations.
Correct Answer:
C
— To manage a collection of disjoint sets
Learn More →
Q. What is the primary use of a priority queue?
A.
Sorting elements
B.
Finding the shortest path
C.
Managing tasks based on priority
D.
Storing elements in a specific order
Show solution
Solution
A priority queue is used to manage tasks based on their priority, allowing for efficient retrieval of the highest (or lowest) priority task.
Correct Answer:
C
— Managing tasks based on priority
Learn More →
Q. What is the purpose of a hash function in a hash table?
A.
To sort the data
B.
To encrypt the data
C.
To map keys to indices
D.
To store data in a binary tree
Show solution
Solution
The hash function's purpose is to map keys to indices in the hash table, allowing for efficient data retrieval.
Correct Answer:
C
— To map keys to indices
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 result of performing a 'decrease key' operation in a min-heap?
A.
The key is increased
B.
The key is decreased and the heap property is maintained
C.
The key is removed
D.
The heap is destroyed
Show solution
Solution
The 'decrease key' operation reduces the value of a key and may require re-heapifying to maintain the heap property.
Correct Answer:
B
— The key is decreased and the heap property is maintained
Learn More →
Q. What is the result of performing a 'Union' operation on two sets A and B in Disjoint Set Union?
A.
A and B remain separate
B.
A and B are merged into one set
C.
A is deleted
D.
B is deleted
Show solution
Solution
Performing a 'Union' operation on two sets A and B merges them into one set, effectively combining their elements.
Correct Answer:
B
— A and B are merged into one set
Learn More →
Q. What is the result of performing a 'Union' operation on two sets in Disjoint Set Union?
A.
It creates a new set containing elements from both sets
B.
It removes one of the sets
C.
It finds the common elements between the two sets
D.
It does nothing if the sets are already connected
Show solution
Solution
The 'Union' operation creates a new set containing elements from both sets, effectively merging them into a single set.
Correct Answer:
A
— It creates a new set containing elements from both sets
Learn More →
Q. What is the result of performing a 'Union' operation on two sets that are already connected in Disjoint Set Union?
A.
The sets remain unchanged
B.
A new set is created
C.
An error occurs
D.
The operation fails
Show solution
Solution
If two sets are already connected, performing a 'Union' operation on them will leave the sets unchanged, as they are already part of the same set.
Correct Answer:
A
— The sets remain unchanged
Learn More →
Q. What is the result of performing a 'Union' operation on two sets that are already connected?
A.
The sets remain unchanged
B.
A new set is created
C.
An error occurs
D.
The sets are split
Show solution
Solution
Performing a 'Union' operation on two sets that are already connected leaves the sets unchanged.
Correct Answer:
A
— The sets remain unchanged
Learn More →
Q. What is the result of performing a heap sort on an array?
A.
An unsorted array
B.
A partially sorted array
C.
A sorted array
D.
A reverse sorted array
Show solution
Solution
Heap sort transforms the array into a max-heap and then repeatedly extracts the maximum element, resulting in a sorted array.
Correct Answer:
C
— A sorted array
Learn More →
Q. What is the result of performing a union operation on two sets A and B in a Disjoint Set Union?
A.
A and B remain separate
B.
A and B are merged into one set
C.
A is deleted
D.
B is deleted
Show solution
Solution
Performing a union operation on two sets A and B merges them into one set, effectively combining their elements.
Correct Answer:
B
— A and B are merged into one set
Learn More →
Q. What is the space complexity of a binary heap storing n elements?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n log n)
Show solution
Solution
The space complexity of a binary heap storing n elements is O(n) because it needs to store all n elements.
Correct Answer:
B
— O(n)
Learn More →
Showing 61 to 90 of 179 (6 Pages)