You are viewing a single comment's thread. Return to all comments →
Hi,
I am a little confused about how it passed the below test case (test case 1 in the question).
INPUT:
2
1 2 4 3 5 6 7
When I printed out the tree, it showed:
ROOT: 3
LEFT CHILD: 2
RIGHT CHILD: 6
ROOT: 2
LEFT CHILD: 1
RIGHT CHILD: 4
ROOT: 1
ROOT: 4
ROOT: 6
LEFT CHILD: 5
RIGHT CHILD: 7
ROOT: 5
ROOT: 7
The code I am using to print out the tree is,
boolean checkBST(Node root) { if(root!=null) { System.out.println("ROOT: " + root.data); if(root.left!=null) { System.out.println("LEFT CHILD: " + root.left.data); } if(root.right!=null) { System.out.println("RIGHT CHILD: " + root.right.data); } } if(root.left!=null) { checkBST(root.left); } if(root.right!=null) { checkBST(root.right); } return true; }
Seems like cookies are disabled on this browser, please enable them to open this website
Trees: Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
Hi,
I am a little confused about how it passed the below test case (test case 1 in the question).
INPUT:
2
1 2 4 3 5 6 7
When I printed out the tree, it showed:
ROOT: 3
LEFT CHILD: 2
RIGHT CHILD: 6
ROOT: 2
LEFT CHILD: 1
RIGHT CHILD: 4
ROOT: 1
ROOT: 4
ROOT: 6
LEFT CHILD: 5
RIGHT CHILD: 7
ROOT: 5
ROOT: 7
The code I am using to print out the tree is,