Question: Java class TreeNode is defined as below: public class TreeNode { public int val; public TreeNode left, right; public TreeNode( int x) { val =

Java class TreeNode is defined as below:

public class TreeNode { public int val; public TreeNode left, right; public TreeNode(int x) { val = x; } }

Suppose you only have the reference of the root, please write a method that returns true if the binary tree is binary search tree; false otherwise.

Please be careful! Checking every node for "greater than the left child and smaller than the right child" is insufficient. The binary tree below is not a binary search tree and your algorithm should correctly detect it.

Java class TreeNode is defined as below: public class TreeNode { public

You may write a private recursive method then a wrapper method.

The code should be in java.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!