Lesson 44 of 86IntermediatePro Interactive Lesson

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

MetricComplexity
Time ComplexityO(n)
Space ComplexityO(1) in-place
Topic ChapterChapter 8: Heaps & Priority Queues
Difficulty LevelIntermediate

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.

Unlock the full course

All 86 lessons across 15 chapters

View pricing

Delete account

This permanently deletes your account and ends any Pro access.