DSA · Reimagined
Trees medium time O(n) space O(1)

Build a Max-Heap

A binary heap is a complete tree where every parent is at least as large as its children — stored as a plain array, with the children of index i at 2i+1 and 2i+2. Heapify works from the last parent backwards, sinking each value to where it belongs.

41035182

A heap is a complete tree: children of index i sit at 2i+1 and 2i+2.

1 / 12

Practice

Machine twin: /dsa-viz-v2/heap-build.json — the full deterministic run as structured data.