Add homework

This commit is contained in:
2026-05-13 15:59:17 -07:00
parent 93f5702d5f
commit c8fe899770
2 changed files with 170 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
# Also do the 2026.05.06 homework
#
# Implement insertion, removal and search in a binary search tree.
# Properties of binary search trees:
# - Each node has at most two children
# - The left subtree of a node contains only nodes with values less than the node's value
# - The right subtree of a node contains only nodes with values greater than the node's value
#
# Example of what such a tree would look like:
# 10
# / \
# 5 15
# / \ \
# 3 7 20
#
# Example of an *invalid* tree:
# 10
# / \
# 5 15
# / \ \
# 3 7 20
# \
# 12
#
# Don't worry about balancing the tree for now, we will cover that later
class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
class BinarySearchTree:
def __init__(self):
self.root = None
def insert(self, value):
# TODO
pass
def remove(self, value):
# TODO
pass
def search(self, value):
# TODO
pass