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

8 class AVLNo de 10 public comparable data 11 public de left 12 public AVLNode g

ID: 3862298 • Letter: 8

Question

8 class AVLNo de 10 public comparable data 11 public de left 12 public AVLNode ght 13 public int height 14 15 default constructor 16e public AVLNode (comparable value) 17 data value; 18 left null 19 20 gh null 21 height 0; 22 23 24 parameterized constructor 25 public AVLNode (Comparable val. de left1. AVLNo right 1) de 26 data value; 27 left left1. 28 29 right right1 30 heigh 0; 31 32 33 The ResetHeight method recomputes height if the 34 left or right subtrees have changed 35 void ResetHeight() 36 37 int leftheight -1; int rightheight -1; 38 89 if (left null) leftheight left height 41 if right null) rightheight righ heigh 42 43 heigh 1 ath rightheigh t) 45

Explanation / Answer

Hi,

The predecessor of a node will be the rightmost node of its left subtree.

so the algorithm would be

set the predecessor as root

   private AVLNode Predecessor(AVLNode nd){
       if (nd!= null) {
               // go to the right most element in the left subtree, it will the
               // predecessor.
               if (nd.left != null) {
                   Node t = nd.left;
                   while (t.right != null) {
                       t = t.right;
                   }
                   predecessor = t.data;
               }  
       }
   }

Here is the function above that was asked thank you

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote