What is the time complexity of building a heap from an array?
What is the time complexity of building a heap from an array?
Approach: Analyze sum of work across tree levels.
O(n). While individual insertions are logarithmic, the total work for building a heap from an unordered array using the bottom-up method is linear.
Follow-up: Explain why it is O(n) and not O(n log n).
Key concepts: linear time, sift down.