Skip to content

FlashcardNot attempted

What makes a heap

Recall it before you reveal

What are the two properties of a binary heap, and how is it stored?

Space to reveal
Show answer & explanation

1. Shape: a *complete* binary tree (every level full, last level filled left to right), so height is O(log n). 2. Order: every parent ≤ its children (min-heap) or ≥ (max-heap). Siblings are unordered.

Stored in an array with no gaps: children of i at 2i+1 and 2i+2, parent at (i−1)>>1. Push = append + bubble up; pop = move the last leaf to the root + sink down.