|
p = inserted node; // p is for sure balanced... pp = p.parent; ppp = pp.parent; while ( pp != root (i.e., ppp != null) ) { if ( ppp is unbalanced ) { /* ----------------------------------------------- Identify node x for the restructure operation ----------------------------------------------- */ z = ppp; y = pp; x = p; p = restructure( x ); break; // Done } p = pp; // traverse twards the root pp = ppp; ppp = ppp.parent; } |
Example:
Example execution of the Re-balance algorithm:
p = inserted node (46) pp = (48) ppp = (50) while loop: ppp (50) is balanced ### Move up 1 level in the tree ### p = pp (48) pp = ppp (50) ppp = ppp.parent (78) ppp (78) is unbalanced z = (78) y = (50) x = (48) p = rebalance( x (48) ) |
|
|
Therefore:
|
|