Question: **Problem:** A binary search tree(BST) relies on the property that keys that are less than the parent are found in the left subtree, and keys

**Problem:**
A binary search tree(BST) relies on the property that keys that are less than the parent are found in the left subtree, and keys that are greater than(or equal) the parent are found in the right subtree.
Implement a BST with the following basic components
1. Create a BST for a list of data (= 10, 5, 8, 2, 4, 12, 11, 4, 9, 15)[ use insert(value) function\
2. Print the values in inorder, preorder, and post order
3. Compute the heigh of the BST
Extra credit: Write delNode(val) function to delet{}e any node from the BST.
Note: Feel free to use the given helper code or write your own
Template :
class Node:
def __init__(self, val):
self.val = val
self.leftChild = None
self.rightChild = None
def get(self):
return self.val
def set(self, val):
self.val = val
def getChildren(self):
children = []
if(self.leftChild != None):
children.append(self.leftChild)
if(self.rightChild != None):
children.append(self.rightChild)
return children
class BST:
def __init__(self):
self.root = None
def setRoot(self, val):
self.root = Node(val)
def insert(self, val):
def insertNode(self, currentNode, val):
def printTree(self, order):
if (order=="1"):
print("Inorder")
self.printBST_In(self.root)
if (order=="2"):
print("Pre-order")
self.printBST_Pre(self.root)
if (order=="3"):
print("Post-order")
self.printBST_Post(self.root)
def printBST_In(self, rt):
def printBST_Pre(self, rt):
def printBST_Post(self, rt):
def bstHeight(self):
Problem: A binary search tree(BST) relies on the property that keys that are less than the parent are found in the left subtree, and keys that are greater than(or equal) the parent are found in the right subtree. Implement a BST with the following basic components 1. Create a BST for a list of data (= 10,5, 8, 2, 4, 12, 11, 4, 9, 15)[ use insert(value) function 2. Print the values in inorder, preorder, and post order 3. Compute the heigh of the BST Extra credit: Write delNode(val) function to delet{}e any node from the BST. Note: Feel free to use the given helper code or write your own
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
