~/ learn/ comp-372/ cards/ The one-page reference sheet (memorize cold)
1 of 4

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/27e1c65d-4a18-4755-a069-1afcd4efa370/flashcard utf-8 LF