On the code which defines a node class whose elements are Co

On the code which defines a node class whose elements are Comparable. Complete the validBST() method so that it returns true when instance defines a subtree that is a valid BST; and false when the subtree violates the definition of how a BST is ordered.

Code:

package edu.buffalo.cse116;

Solution

CODE:

public boolean validBst(){

return isBST(parent, Integer.min , Integer.max);

    }

public boolean isBST(BSTNode<E> parent , int min , int max)

    { if (parent== null)

            return true;

if (parent.data < min || parent.data > max)

            return false;

return (isBST(parent.left, min, parent.data-1) && isBST(parent.right, parent.data+1, max));

    }

On the code which defines a node class whose elements are Comparable. Complete the validBST() method so that it returns true when instance defines a subtree tha

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site