In a priority queue, which data structure is typically used to ensure efficient access to the highest (or lowest) priority element?
a) Stack
b) Queue
c) Binary Heap
d) Hash Table
Answer:
c) Binary Heap
Explanation:
A binary heap is commonly used to implement a priority queue. In a binary heap, the highest (or lowest) priority element is always at the root, allowing for efficient access in O(1) time. Insertion and deletion operations in a heap take O(log n) time, making it well-suited for priority queues.
A binary heap can be implemented as a max-heap or min-heap, depending on whether the priority queue is meant to retrieve the maximum or minimum element.
Other data structures, like unsorted arrays or linked lists, are less efficient for priority queues because they require linear time to find the element with the highest priority.
Reference:
DSA (Data Structures and Algorithms) MCQ Questions and Answers