Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have tried to find this many different waysbut can\'t find one that has multip

ID: 3616457 • Letter: I

Question

I have tried to find this many different waysbut can't find one that has multiple rotations where a doublerotation is counted as one. Please help. Show an AVL tree for which an addition willcause multiple rotations. We count a double rotation as onerotation not two (it’s just fancier). I am new to Cramster but I know how itworks and I will give Lifesaver rating. I have tried to find this many different waysbut can't find one that has multiple rotations where a doublerotation is counted as one. Please help. Show an AVL tree for which an addition willcause multiple rotations. We count a double rotation as onerotation not two (it’s just fancier). I am new to Cramster but I know how itworks and I will give Lifesaver rating.

Explanation / Answer

/* This is the function used to insert nodes satisfying the AVLcondition.*/

TreeNode<int>*   avlInsert(TreeNode<int>*root, int info)

{

    if( info < root->getInfo() ){

       root->setLeft(avlInsert(root->getLeft(), info));

        int htdiff =height(root->getLeft()) – height(root->getRight());

        if( htdiff == 2 )

           if( info < root->getLeft()->getInfo() ) // outsideinsertion case

             root = singleRightRotation( root );

           else // inside insertion case

             root = doubleLeftRightRotation( root );

  }

   else if(info > root->getInfo() ) {

       root->setRight(avlInsert(root->getRight(),info));

        int htdiff =height(root->getRight()) – height(root->getLeft());

        if( htdiff == 2 )

           if( info > root->getRight()->getInfo() )

               root = singleLeftRotation( root );

           else

               root = doubleRightLeftRotation( root );

    // else a node with info is already in thetree. In
   // case, reset the height of this root node.

    int ht = Max(height(root->getLeft()),height(root->getRight()));

    root->setHeight( ht + 1 ); // new heightfor root.

    return root;

}