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

python - Installing PyDev in eclipse is failed -

PHP OOP-based login system -

c# - Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment -