Heapsort (min-heap) — C code & step-by-step simulation

0-indexed min-heap · children of i: 2i+1 and 2i+2 · parent of i: (i−1)/2 · sorts in DESCENDING order · in-place, O(N log N) · step with the buttons or the arrow keys

C implementation

Call stack

Heap as a binary tree

Array h

heap region sorted suffix current position (i) children being compared (c) swap

What is happening