You are viewing a single comment's thread. Return to all comments →
Can anyone help me understand why this doesn't work?
from queue import Queue def node_evaluation(node, visited): if node.data in visited: return False visited.add(node.data) if node.left: print(f"L {node.data} {node.left.data}") if node.data <= node.left.data: return False elif not node_evaluation(node.left, visited): return False if node.right: print(f"R {node.data} {node.right.data}") if node.data >= node.right.data: return False elif not node_evaluation(node.right, visited): return False return True def check_binary_search_tree_(root): visited = set() if root is None: return True return node_evaluation(root, visited)
Seems like cookies are disabled on this browser, please enable them to open this website
Is This a Binary Search Tree?
You are viewing a single comment's thread. Return to all comments →
Can anyone help me understand why this doesn't work?