Created
March 14, 2015 04:01
-
-
Save lettergram/5adfd16ff0518548a386 to your computer and use it in GitHub Desktop.
Search key in BST
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
''' | |
Discovers if a 'key' is present in the binary tree | |
''' | |
def find(self, root, key): | |
if root is None or root.data is key: | |
return root | |
elif key < root.data: | |
return self.find(root.left, key) | |
else: | |
return self.find(root.right, key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment