Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
restructured binary search tree
  • Loading branch information
Idong Essien committed Jun 19, 2020
commit 72a3c2f961538d462842b37851577217cc76bd2e
12 changes: 5 additions & 7 deletions names/binary_search_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,24 @@ def __init__(self, value):
self.right = None
self.count = 1

# insert the given value into the tree
''' Insert given value into tree . If no Node , insert new node . If Node , implement recursion . '''

''' If tree contains value , return TRUE . Return False otherwise . '''

def insert(self, value):
if value < self.value:
if not self.left:
# if node does not exist, insert new node
self.left = BinarySearchTree(value)
else:
# if node exists, recurse
self.left.insert(value)
else:
# value is >= node
if not self.right:
self.right = BinarySearchTree(value)
else:
self.right.insert(value)

# Return True if the tree contains the value
# False if it does not
''' Implement recursion '''
def contains(self, target):
# recursive solution
if target == self.value:
return True
elif target < self.value:
Expand Down