Skip to content

Instantly share code, notes, and snippets.

@pallabpain
Created September 21, 2016 18:11
Show Gist options
  • Save pallabpain/f0dc9514ee56e82d5a468752adf9a061 to your computer and use it in GitHub Desktop.
Save pallabpain/f0dc9514ee56e82d5a468752adf9a061 to your computer and use it in GitHub Desktop.
Searching in an unsorted binary tree
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