Consider Following Bnode Class Class Bnode Int Val Bnode Left Right Boolean Isbst Bnode U Q37208006

Consider the following BNode class:

class BNode {

int val;

BNode left, right;

boolean isBST(BNode u){…}
boolean isBST(int min, BNode u, int max){…}

}

Note that our BNodes do not have parent pointers! It has amethod isBST(u) that returns true iff the subtree rooted at u is aBST. Please write the code for isBST(u) and its helper methodisBST(min, u, max) which will return false if the keys in thesubtree at u do not lie in the range (min, max). The helper methodmust be recursive.


Answer


intisBST(BNode  root)

{

    // if the tree is empty

    if(root ==null)

        returntrue;

    // if the current node disobeys the BSTproperty

    // use the isBST(min,

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.