Answered step by step
Verified Expert Solution
Link Copied!
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 $B(x)$. 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 -1,0,1 when we have a legal AVL tree and therefore only take 2 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 (\textit{hint}: split into cases according to the values of $T.B$ and $T.right.B$)
\begin{minted}{java}
Tree rotateLeft(Tree T){
Tree x = T.right;
T.right = x.left;
x.left = T;
return x;
}
\end{minted}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students explore these related Databases questions