4223161584
AlgoPlus//structures / binary-heap
Read the theory

Binary Heap · Max-Heap

Every parent beats its children; stored compactly as an array.

Size
6
Max (root)
42
Legend
Comparing
Swapping
Node
AI Tutor Workspace
In a nutshell
A binary heap is a tree built for one job: always knowing the most extreme item. Every parent beats both its children — smaller in a min-heap, larger in a max-heap — so the winner always sits at the very top, one glance away. It is stored compactly as a plain array with no pointers: the node at position i finds its children at 2i+1 and 2i+2. Adding an item or removing the top each take only about log n swaps to restore the rule. Note it is not fully sorted — only the root is guaranteed extreme.
Ready
Press play to begin the cinematic walkthrough.
A complete binary tree where every parent beats its children. As an array, parent i's children are 2i+1 and 2i+2 — no pointers needed.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Binary Heap · Max-Heap.