Question: 1 . Implement a BST Class Create a Node class that represents a node in a binary tree with: o data: the value stored at
Implement a BST Class
Create a Node class that represents a node in a binary tree with:
o data: the value stored at the node.
o left: the left child.
o right: the right child.
Then, create a BST class with the following functions:
a Insert: A method insertself value to insert a value into the BST
b Find: A method findself value that returns the node if it exists in the tree
or None if it doesn't.
Delete a Node
Implement a method deleteself value to remove a node from the BST Ensure you
handle all three cases:
o Node to be deleted has no children leaf node
o Node to be deleted has one child.
o Node to be deleted has two children replace it with its inorder successor or
predecessor
Preorder Traversal
Write a method preordertraversalself that performs a preorder traversal of the
tree root left right and prints the values in this order.
Main Program
Write a main program that:
o Creates an empty BST
o Inserts the following values into the tree:
o Deletes the node with value a node with two children
o Deletes the node with value a leaf node
o Deletes the node with value a node with one child
o Finds the node with value
o Prints the preorder traversal of the tree after each deletion
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
