Skip to content

Commit

Permalink
#231 migrate 6.2-7
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtask committed Sep 23, 2024
1 parent aca5cfe commit 10b53b6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion chapter6/sections/2/7.tex
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
\workinprogress % TODO
The worst case for \proc{Max-Heapify} occurs when the procedure is called for the root of the heap (i.e., for $i=1$), and when the test in line 8 comes up true in every recursive call but the last, causing the procedure to descend to the lowest level of the heap.
By \refExercise{6.1-2}, in an $n$-element heap the longest simple path from the root down to a leaf consists of $h=\lfloor\lg n\rfloor$ edges and this is how many times the procedure is called recursively in the worst case.
The cost incurred at each level of the recursion is $\Theta(1)$, so the worst-case running time is $\Omega(\lg n)$.

An example heap $A$ for which the call $\proc{Max-Heapify}(A,1)$ performs the operations described above is one in which the root has value 0 and every other node has value 1.

0 comments on commit 10b53b6

Please sign in to comment.