Skip to content

Update bst.py #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
14 changes: 7 additions & 7 deletions Binary_Search_Tree/bst.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ def addHelper(self,root,data):
# case for reaching current leafs, base cases
if root.val < data and root.right == None:
root.right = BST(data,None,None)
return "insertion completed"
return "Insertion completed"
elif root.val > data and root.left == None:
root.left = BST(data,None,None)
return "insertion completed"
return "Insertion completed"

# else we continue tracing downwards
if root.val < data:
return self.add(root.right,data)
elif root.val > data:
return self.add(root.left,data)
else:
return "insertion failed: duplicate value"
return "Insertion failed: duplicate value"

def add(self,root,data):
if root == None:
Expand All @@ -32,7 +32,7 @@ def restructdata(self,root):
# base case: we reach a leaf
if root == None or (root.left == None and root.right == None):
root = None
return "restructure finished"
return "Restructure finished"

# need dummy nodes to compare target value to children value
v1 = float('-inf')
Expand All @@ -55,7 +55,7 @@ def restructdata(self,root):

def removeHelper(self,root,data):
if root == None:
return "deletion failed: could not find value"
return "Deletion failed: could not find value"

# adhering to typical bst properties
if root.val < data:
Expand All @@ -82,9 +82,9 @@ def removeHelper(self,root,data):

def remove(self,root,data):
if root == None:
return "deletion failed: deleting from an empty tree"
return "Deletion failed: deleting from an empty tree"
return self.removeHelper(root,data)