Wednesday, June 18, 2008

Heapify

Heapify (H, i)

The above Procedure fixes the heap for index ‘i’ where ‘i’ refers to the index such that the tree rooted at H[i] is a heap. This Procedure recursively calls itself until the given heap is fixed.
Step 1 Left child, and right child, initialization
set l  Lchild (i)
set r  Rchild (i)
Step 2 Place the maximum value, left child
if (l  heap-size [H] and H [l] > H[i]) then
set max  l
else
set max  i
Step 3 Place the maximum value, right child
if (r  heap-size [H] and H [r] > H [max]) then
set max  r
Step 4 Checking with parent
if (max  i) then
set H [i]  H [max]
Step 5 fixing of heap
Call to Heapify (H, max)

1 comment:

raynnowui21 said...

I found your blog website on google and test a few of your early posts. Proceed to maintain up the superb operate. I simply extra up your RSS feed to my MSN News Reader. In search of forward to reading extra from you later on!… online casino bonus