~/ learn/ comp-372/ cards/ Exam War Room: Final Review, Reference Sheets & Mock Exam
1 of 40

Time to BUILD-MAX-HEAP on n elements — and the classic wrong answer?

Time to BUILD-MAX-HEAP on n elements — and the classic wrong answer?

Answer

Θ(n); the classic trap answer is Θ(n lg n).

Bottom-up MAX-HEAPIFY costs Σ over heights of (nodes at height h)·O(h) = O(n·Σ h/2ʰ) = O(n). Only if you bound each of the n heapify calls by lg n do you get the loose Θ(n lg n).

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/03ac45f9-8f11-4052-b04f-4270d6526a1d/flashcard utf-8 LF