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

Change these methods below into recursive ones. protected BinaryNode findMin( Bi

ID: 3689639 • Letter: C

Question

Change these methods below into recursive ones.

protected BinaryNode findMin( BinaryNode t )
    {
        if( t != null )
            while( t.left != null )
                t = t.left;

        return t;
    }

  
    private BinaryNode findMax( BinaryNode t )
    {
        if( t != null )
            while( t.right != null )
                t = t.right;

        return t;
    }

  
    private BinaryNode find( AnyType x, BinaryNode t )
    {
        while( t != null )
        {
            if( x.compareTo( t.element ) < 0 )
                t = t.left;
            else if( x.compareTo( t.element ) > 0 )
                t = t.right;
            else
                return t;    // Match
        }
      
        return null;         // Not found
    }

Explanation / Answer

protected BinaryNode findMin( BinaryNode t ) { if( t != null ) return findMin(t.left); else return t; } private BinaryNode findMax( BinaryNode t ) { if( t != null ) return findMax(t.right); else return t; } private BinaryNode find( AnyType x, BinaryNode t ) { if( t != null ) { if( x.compareTo( t.element ) < 0 ) find(x,t.left); else if( x.compareTo( t.element ) > 0 ) find(x,t.right); else return t; // Match } return null; // Not found }
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