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)

3 comments:

Leslie Lim said...

Thanks to the writer of this article. I appreciate your effort in making this informational blogs. I know it's not easy to do this but you have done a really great job. Congrats. I'm pretty sure your readers enjoying it a lots.


Rica
www.imarksweb.org

Leslie Lim said...

Thanks to the writer of this article. I appreciate your effort in making this informational blogs. I know it's not easy to do this but you have done a really great job. Congrats. I'm pretty sure your readers enjoying it a lots.


Rica
www.imarksweb.org

Silvia Jacinto said...

Thanks for sharing such a wonderful article, I hope you could inspire more people. Visit my site too.

n8fan.net

www.n8fan.net