Q. How does a priority queue differ from a regular queue?
A.
It allows duplicate elements
B.
It processes elements based on priority
C.
It can only hold integers
D.
It is implemented using arrays only
Show solution
Solution
A priority queue processes elements based on their priority rather than the order they were added, unlike a regular queue.
Correct Answer:
B
— It processes elements based on priority
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 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 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, 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. 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 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 time complexity of inserting an element into a binary heap used as a priority queue?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
Inserting an element into a binary heap takes O(log n) time due to the need to maintain the heap property.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of removing the highest priority element from a binary heap?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
Removing the highest priority element from a binary heap has a time complexity of O(log n) due to the need to re-heapify.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of removing the highest priority element from a priority queue implemented with a binary heap?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
Removing the highest priority element from a binary heap takes O(log n) time due to the need to maintain the heap property after removal.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the worst-case time complexity for deleting the minimum element from a binary heap?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
Deleting the minimum element from a binary heap takes O(log n) time as it requires re-heapifying the structure.
Correct Answer:
B
— O(log n)
Learn More →
Q. Which algorithm uses a priority queue to find the minimum spanning tree?
A.
Kruskal's algorithm
B.
Prim's algorithm
C.
Dijkstra's algorithm
D.
Bellman-Ford algorithm
Show solution
Solution
Prim's algorithm uses a priority queue to efficiently select the next edge with the minimum weight to add to the spanning tree.
Correct Answer:
B
— Prim's algorithm
Learn More →
Q. Which data structure is typically used to implement a priority queue?
A.
Array
B.
Linked List
C.
Heap
D.
Stack
Show solution
Solution
Heaps are commonly used to implement priority queues because they allow for efficient insertion and removal of the highest (or lowest) priority element.
Correct Answer:
C
— Heap
Learn More →
Q. Which of the following algorithms uses a priority queue to find the shortest path in a graph?
A.
Depth-First Search
B.
Dijkstra's Algorithm
C.
Bubble Sort
D.
Binary Search
Show solution
Solution
Dijkstra's Algorithm uses a priority queue to efficiently find the shortest path from a source node to all other nodes in a graph.
Correct Answer:
B
— Dijkstra's Algorithm
Learn More →
Q. Which of the following algorithms uses a priority queue?
A.
Merge Sort
B.
Dijkstra's Algorithm
C.
Binary Search
D.
Quick Sort
Show solution
Solution
Dijkstra's Algorithm uses a priority queue to efficiently select the next vertex with the smallest tentative distance.
Correct Answer:
B
— Dijkstra's Algorithm
Learn More →
Q. Which of the following is NOT a typical application of heaps?
A.
Heap sort
B.
Implementing a priority queue
C.
Finding the median of a list
D.
Graph traversal
Show solution
Solution
Graph traversal is not a typical application of heaps; instead, heaps are used for sorting, priority queues, and finding medians.
Correct Answer:
D
— Graph traversal
Learn More →
Q. Which of the following is NOT a typical use case for priority queues?
A.
Job scheduling
B.
Pathfinding algorithms
C.
Data compression
D.
Implementing a LIFO structure
Show solution
Solution
Implementing a LIFO structure is not a typical use case for priority queues; that is the function of stacks.
Correct Answer:
D
— Implementing a LIFO structure
Learn More →
Showing 1 to 19 of 19 (1 Pages)