Module M21 · 21 of 35 in teaching order · Intermediate

Heaps and Priority Queues

The array-backed heap, sift operations, O(n) heapify and heap sort.

Lessons

  1. The array-backed binary heap: the heap property, sift up, sift down, O(n) heapify, and the priority queues of C#, Python, Java and C++ with their min/max defaults.

  2. 2Heap sort~35 min

    Heap sort in place: build a max-heap in O(n), then move the maximum to the end n − 1 times. O(n log n) in every case, O(1) extra space, not stable.

Topics this module covers

The full module scope. Topics without a lesson above are not written yet.

  • min/max
  • array representation
  • insert/extract
  • sift up/down
  • heapify
  • priority queue
  • heap sort
  • top K
  • two heaps
  • implementation

Builds toward