Convert from max heap to min heap -


got heap:

         10         /  \        9    8       / \  / \      7  6  5  4     / \ /    3  2 1 

and i'm going show each step when convert minimum heap maximum. i'm not sure how it, please? thanks.

try go throught tree levels, starting lowest node
if heap represented array, simple
1. step
comparing 1 6, , switching:

      10      /  \     9    8    / \  / \   7  1  5  4  / \ / 3  2 6 

next step - comparing 2 , 7 (and switching):

      10      /  \     9    8    / \  / \   2  1  5  4  / \ / 3  7 6 

next step - comparing 3 , 2 (and noswitching):

      10      /  \     9    8    / \  / \   2  1  5  4  / \ / 3  7 6 

next step - comparing 4 , 8 (and switching):

      10      /  \     9    4    / \  / \   2  1  5  8  / \ / 3  7 6 

etc. should create min-heap


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -