Bottom-Up Heap Construction
Start at the last internal node and sift down toward the leaves as needed.
Core Intuition & How It Works
Bottom-up heap construction (Floyd’s heapify) converts an arbitrary array into a valid binary heap in O(n) linear time by sifting down from the last internal node to the root. Most nodes sit near the bottom and move very short distances.
In the Byte Sized Algorithms interactive classroom, you can step forward and backward through this algorithm with your keyboard while watching the visual diagram, memory state, and highlighted pseudocode update together.
Time & Space Complexity
| Metric | Complexity |
|---|---|
| Time Complexity | O(n) |
| Space Complexity | O(1) in-place |
| Topic Chapter | Chapter 8: Heaps & Priority Queues |
| Difficulty Level | Intermediate |
Key Pattern to Recognize
Start sifting down at index floor(n / 2) - 1 down to 0, skipping all leaf nodes since leaves are trivially valid heaps.
Common Pitfalls & Edge Cases
Assuming building a heap takes O(n log n) because each sift-down is O(log n)—the geometric series of heights sums to O(n).
Real-World & Technical Interview Applications
Heapsort initialization, batch priority queue construction, and linear-time k-smallest preprocessing.