- Trees: Is This a Binary Search Tree?
- Discussions
Trees: Is This a Binary Search Tree?
Trees: Is This a Binary Search Tree?
+ 0 comments This problem is totally broken with Java 8. Boilerplate is hidden, but broken.
+ 0 comments Very poor solution with the hidden/unviewable code for C++. You cannot include STL headers, you cannot use types you wish, any debug output breaks your results.
This task is terribad.
+ 0 comments Sure seems that the Java 8 template is broken. You will be hit with a "Cannot find or load main class" Exception. Switch to Java 17 and you have to implement the boilerplate yourself. Just switch to Python and roll with it, if you're having trouble.
+ 0 comments The code provided in python always print a "No" answer at the end, even if no revelant code is written. is It a bug?
+ 0 comments An alternative solution I've made is to do an in order traversal of the tree. And since every subsequent node must be greater than the precedent node, any node that fails this condition means that the tree is not a valid binary search tree.
def checkBST(root): lastItem = None result = True def inOrderTraversal(node): nonlocal lastItem nonlocal result if node.left != None: inOrderTraversal(node.left) if lastItem != None and node.data <= lastItem: result = False lastItem = node.data if node.right != None: inOrderTraversal(node.right) inOrderTraversal(root) return result
Sort 788 Discussions, By:
Please Login in order to post a comment