Question: Read the following code and fill in blank #1. TreeNode* Balance(TreeNode* T) // Checks and balances the subtree T. { int balanceFactor = Difference(T); if

Read the following code and fill in blank #1.

TreeNode* Balance(TreeNode* T)

// Checks and balances the subtree T.

{

int balanceFactor = Difference(T);

if (balanceFactor > 1) {

if (Difference(T->left) > 1)

return RotateRight(T); // #1

else

return RotateLeftRight(T); // #2

}

else if (balanceFactor < -1) {

if (Difference(T->right) < 0)

return RotateLeft(T); // #3

else

return RotateRightLeft(T); // #4

}

else

return T;

}

[1] RotateLeft(T)

[2] RotateLeftright(T)

[3] RotateRight(T)

[4] RotateRightLeft(T)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!