P-4.6 Heaps and Priority Ordering
You can explain the heap property, implement a binary heap in an array, and say which problems need the smallest item repeatedly rather than a full ordering.
A heap answers one question well: what is the smallest thing left. It does not keep everything sorted, and that is exactly why it is cheaper than a structure that does. The neat part is the representation, because a complete binary tree fits in a plain array with the children of a position found by arithmetic, so there are no nodes and no addresses at all.
Work through these
The heap property: each parent is smaller than its children
Ordering is enforced only between a parent and its own children, never across a level. That much weaker promise is enough to know where the smallest item is and cheap enough to maintain.
Algorithms, 4th Edition — companion site · ReferenceA complete tree stored in an array, with children found by arithmetic
Filling every level left to right means position and structure agree, so a child sits at twice the index and a parent at half. No links are stored at all.
Sifting up on insert and sifting down on removal
A new item is placed at the end and moved up while it is out of order; removing the top moves the last item to the front and sinks it. Both walk one path of the tree.
Priority ordering as a use of a heap, not a structure of its own
Serving the most urgent item rather than the earliest is the pattern behind schedulers, event simulation and several graph algorithms. A heap is the usual implementation.
Heapsort, and why building a heap is faster than it looks
Repeatedly removing the top gives a sorted sequence in place with no extra memory. Building the heap in the first place costs linear time rather than the obvious bound, which is a result worth working through.
Sign in to keep your progress.
Free resources
We haven't checked most of these for screen reader use yet.
Links last checked 31 Aug 2026.
Stuck here?
Ask a mentor. A real person answers, and they can see exactly which topic you're on. Usually within a couple of working days.
Checking your session…
Topics shown in module order.