Stage 1 · Code
Heaps & Priority Queues
Min Heap
Heap property, array representation, and heapify operations.
Heap Property
A min heap is a complete binary tree where each node's value ≤ its children's values. Root is always minimum. Max heap reverses the inequality. Heaps enable O(1) min/max access and O(log n) insertion/deletion.
Array Representation
Heaps use array (slice) with implicit tree structure. For 0-indexed array: left child = 2*i+1, right child = 2*i+2, parent = (i-1)/2. No pointers needed.
Core Operations
Heapify
Build heap from unsorted array in O(n) by sifting down from last non-leaf node to root. Better than n pushes (O(n log n)).
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.