RK DSA Studio

Max-heap

A complete binary tree whose parent is no smaller than either child. Its root is a maximum; the whole array is not sorted.

Remember: Largest at root; repair along a path.

Example: [9,4,7] is a max-heap; extracting 9 leaves root 7.

Time: O(n) build. Auxiliary space: O(1) extra.

Formula: parent = floor((i − 1) / 2); left = 2i + 1; right = 2i + 2

Zero-based array. The root has no parent; children exist only if their indices are below n. Index lookup: O(1), insert/extract: O(log n), after initial O(n) construction.

Complexities describe the underlying algorithm; tutorial snapshots and rendering can use additional resources.

The interactive workspace loads here when JavaScript is available. You can still browse the learning notes and links above without it.