LOGBOOK

HELP

Quiz Entry - updated: 2026.11.26

How does a priority queue implemented with an unsorted list perform, and which sorting algorithm does PQ-Sort become with it?

insert is $O(1)$ (just append), but min and removeMin are $O(n)$ because the whole list must be scanned for the smallest key. PQ-Sort with it is selection-sort, $O(n^2)$.

With no order to maintain, inserting is trivial: put the new entry at the front or the back. The price is paid when reading: the smallest key could be anywhere, so every min() and removeMin() walks all $n$ entries.

In PQ-Sort that means phase 1 is cheap ($n$ appends, $O(n)$) and phase 2 does all the work: it repeatedly scans the remaining elements for the smallest one and takes it out. That is exactly selection-sort, and the scans cost $n + (n-1) + \dots + 1 = O(n^2)$.

This implementation is the right choice when inserts vastly outnumber removals, or when inserting must be fast and reading can wait. A weather radar is a real example: each echo has to be captured the moment it returns from the hardware, while the processing can happen afterwards. Whether a structure should create order when data goes in or when it comes out is a recurring design question, and the answer depends on which side is time-critical.

Go deeper:

  • doc Selection sort โ€” the algorithm PQ-Sort becomes with an unsorted list, with an animation.

From Quiz: ADS / Priority Queues and Heaps | Updated: Nov 26, 2026