Question: You should use python programming language only The task you have to complete is the Task2. But it first you need to complete the binary
You should use python programming language only
The task you have to complete is the Task2. But it first you need to complete the binary tree problem in the task1 as depicted below. First understand the task2 and then with the help of task 1 do the Task 2

The partially completed python template for the above code is as follows,
In the code below, the import function is used to import the binary tree code that is solved in the task 1. Therefore solve the task 1 binary tree to complete the code of task 2.
import PBT_150000X.py def AddValue (BinTree, NewValue): #Implement this method and return appropriate value. return None def DeleteValue (BinTree, DelValue): #Implement this method and return appropriate value. return None def SearchValue (BinTree, SchValue): #Implement this method and return appropriate value. return None def PrintTree (BinTree): #Implement this method and return appropriate value. return None
Task 1 for the above problem is as follows,



The partially completed code (PBT_150000X.py) for the binary tree required for the task 1 is given below.

class BTNode: def __init__(self, val): self.lChild = None self.rChild = None self.value = val
class BinaryTree: def __init__(self): self.root = None
def AddLeftChild (ParentNode, ChildValue): if(ParentNode.lChild != None): return -1 ParentNode.lChild = BTNode(ChildValue) return 1
def AddRightChild (ParentNode, ChildValue): if(ParentNode.rChild != None): return -1 ParentNode.rChild = BTNode(ChildValue) return 1
def GetLeftChild (Node): return Node.lChild
def GetRightChild (Node): return Node.rChild
def CreateBinaryTree (ElementList): #Implement this method and return appropriate value. return None
def ExpandBinaryTree (BinTree, NewElementList): #Implement this method and return appropriate value. return None
def TraverseInOrder(BinTree): #Implement this method and return appropriate value. return None
def TraversePreOrder(BinTree): #Implement this method and return appropriate value. return None
def TraversePostOrder(BinTree): #Implement this method and return appropriate value. return None
Task 2: Implementing a Binary Search Tree In the second task of the lab, you are expected to extend your binary tree into a binary search tree Your binary search tree should support following operations def AddValue (BinTree, Newvalue) This function will add the value specified by "NewValue" to the binary tree specified by "BinTree" if the value is not present in the tree already (for simplicity we assume the values in the binary search tree will be unique). It returns 1 if addition is successful and returns -1 in failure. Keep in mind that the insertion should maintain the binary search tree property in the binary tree. def DeleteValue (BinTree, DelValue) This function will delete the value specified by "DelValue" from the tree specified by "BinTree" if the value is present in the tree. It returns the deleted element if deletion is successful and returns None in failure. Keep in mind that the deletion should maintain the binary search tree property in the binary tree def SearchValue (BinTree, SchValue) This function will return a pointer to the node which contains value specified by "SchValue" in the tree specified by"BinTree" if the value is present in the tree. If the value is not in the tree, it will return None. Keep in mind that you are searching in a binary search tree. void PrintTree (BinTree) This function will print the values in the tree specified by "BinTree" in sorted order
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
