Maintaining the Heap Property
Heapify ( A, i )

Action of the Heapify algorithm
Heapify ( A, i )
-
l ¬ Left ( i )
-
r ¬ Right ( i )
-
if l £ heap-size[A] and A[l] > A[i]
-
then largest ¬ l
-
else largest ¬ i
-
if r £ heap-size[A] abd A[r] > A[largest]
-
then largest ¬ r
-
if largest ¹ i
-
then exchange A[i] « A[largest]
-
Heapify ( A, largest) // so
that the heap property is not destroyed
What is the running time of Heapify ( A, i )?
T (n) £ T ( 2/3 n ) + Q (1) where T ( 2/3 n ) is the cost of fixing the sub tree and Q (1) is the cost of the exchange.
The worst case -- always branch 1 direction.
T (n) = ( lg n ) :: case 2 of the Master Theorem.
|