performance - Why does BUILD-MAX-HEAP take time O(n) while HEAP-SORT takes O(nlgn) time? -


while reading "introduction algorithms", wondering why heapsort takes time o(nlgn), whereas build-max-heap takes time o(n).

the heapsort begins loop @ a.length downto 2, calling max-heapify.

the build-max-heap begins loop @ floor of a.length/2 downto 1, calling max-heapify.

the max-heapify takes time o(lgn). wondering causes build-max-heap more faster heapsort.

in building heap, "heapify" element starting bottom, when sorting it, "heapify" top element. in both case, height varying point note:

*in building heap, maximum elements heapify lie @ bottom , less height heapify hence o(n), while sorting heapify top element. though height decreasing not advantageous in prior case. *

i hope understand i'm trying say.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -