Question: In this lab, you would be writing a BinarySearchTree and BinaryTreeNode. As a refresher: the nodes contained in the left subtree must be LESS THAN
In this lab, you would be writing a BinarySearchTree and BinaryTreeNode. As a refresher: the nodes contained in the left subtree must be LESS THAN the parent and nodes contained in the right subtree must be GREATER the parent for simplicity, you can assume all the integers are unique Here is some code to help you get started: class Node: def initself initdata: self.data initdata self.left None self.right None self.parent None class BST: def initself: self.root None You have to implement the following functions in BinarySearchTree class: insert: Should take in a value to be inserted and return nothing. It needs to insert this such that the tree remains a BST see the italicized text above Delete: The deletion process in a Binary Search Tree BST involves handling three main cases: Deleting a node with no children a leaf node: Remove the node directly without affecting the rest of the tree structure. Deleting a node with one child: Replace the node with its child, ensuring the tree's ordering property is maintained. Deleting a node with two children: Find the node's inorder successor or predecessor typically the minimum or maximum node in its right or left subtree, replace the node to be deleted with this successor node, and then delete the successor node from its original position in the subtree. Adjust the tree to preserve the BST structure after 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
