~/ 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/a84c8165-9fe5-44dc-aed6-2ba138360e96/flashcard utf-8 LF