Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started