What is the most appropriate data structure for implementing a priority queue?

2010

What is the most appropriate data structure for implementing a priority queue?

Answer: A. HeapConceptA priority queue removes the item with the highest or lowest priority, rather than necessarily removing the earliest inserted item. An efficient…

  1. A.

    Heap

  2. B.

    Circular array

  3. C.

    Linked list

  4. D.

    Binary tree

Attempted by 214 students.

Show answer & explanation

Correct answer: A

Concept

A priority queue removes the item with the highest or lowest priority, rather than necessarily removing the earliest inserted item.

An efficient implementation should expose the extremal item quickly and restore its ordering efficiently after insertion or removal.

Application

  1. Consider a max-priority queue receiving priorities 20, 50, and 30. In a max-heap, the largest priority is kept at the root, so 50 is immediately accessible.

  2. Inserting a value moves it upward only along one root-to-leaf path, so insertion takes O(log n) time.

  3. Removing the root replaces it with the last element and restores heap order along one path, so removal takes O(log n) time.

Cross-check and contrast

  • Heap: the heap-order invariant directly maintains an extremal element at the root.

  • Circular array: it efficiently represents a FIFO queue, but an unsorted version requires a linear scan to locate the highest-priority item.

  • Linked list: it offers flexible insertion, but an unordered version requires a linear scan to locate the highest-priority item.

  • Binary tree: the number-of-children rule alone does not order keys; a heap is the ordered tree structure needed here.

Therefore, a heap is the most appropriate data structure among the given choices.

Explore the full course: Coding For Placement

Loading lesson…