Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For an AVL tree, decisions about which rotation to perform must be made based on the balance factor $B ( x ) $ . This
For an AVL tree, decisions about which rotation to perform must be made based on the balance factor $Bx$ This coefficient is calculated as the difference between the heights of the trees, one way would be to store the height of each tree and keep track of it We want to implement rotateLeft to maintain the balance factor $B$ stored for each tree. These numbers should only take the values when we have a legal AVL tree and therefore only take bits of memory.
Below is an implementation of rotateLeft without keeping track of $B$ and we assume that $B$ is a field in $T$
Find out how the code below needs to be changed to calculate the new $B$ values. Assume that the tree $T$ is a legal AVL tree, but possibly the new tree will not be a legal AVL tree. Describe in which cases the AVL tree is legal after left rotation textithint: split into cases according to the values of $TB$ and $Tright.B$
beginmintedjava
Tree rotateLeftTree T
Tree x Tright;
Tright xleft;
xleft T;
return x;
endminted
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