Created
March 16, 2020 15:39
-
-
Save naveen17797/46c05e005b196cfdf56232d3e1b94801 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_binary_search_tree_(root): | |
nodes = [root] | |
isTreeValid = True | |
while len(nodes) != 0: | |
currentNodes = [i for i in nodes] | |
nodes.clear() | |
for node in currentNodes: | |
print("node data is " + str(node.data)) | |
if node.left != None: | |
print("node left data is " + str(node.left.data)) | |
if node.right != None: | |
print("node right data is " + str(node.right.data)) | |
if node.left != None and node.left.data > node.data: | |
return False | |
if node.right != None and node.right.data < node.data: | |
return False | |
if node.left != None: | |
nodes.append(node.left) | |
if node.right != None: | |
nodes.append(node.right) | |
return isTreeValid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment