Created
September 21, 2016 18:11
-
-
Save pallabpain/f0dc9514ee56e82d5a468752adf9a061 to your computer and use it in GitHub Desktop.
Searching in an unsorted binary tree
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
class Node(object): | |
def __init__(self, value, left, right): | |
self.value = value | |
self.left = left | |
self.right = right | |
def find(root, target): | |
if root is None: | |
return None | |
if root.value == target: | |
return root | |
x = find(root.left, target) | |
if x is not None: | |
return x | |
x = find(root.right, target) | |
if x is not None: | |
return x | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment