Question: Python programming only You have two tasks here. First read the task two and understand what's required to be done. Then with the help of

Python programming only

You have two tasks here. First read the task two and understand what's required to be done. Then with the help of task1 stated below complete the code required for the task 2.

Python programming only You have two tasks here. First read the task

You are also expected to test and demonstrate your implementation using a random binary search tree.

You should complete the code and verify that your code works using suitable test cases.

In addition, you are required to demonstrate your code by creating a binary search tree using some random numbers and then performing different operations on this binary search tree

The required partially completed codes are given below.

Partially completed binary tree

Follow the intructions to complete the binary tree as stated below.

two and understand what's required to be done. Then with the help

class BTNode:

def __init__(self, val):

self.lChild = None

self.rChild = None

self.value = val

def AddLeftChild (self, NewValue):

if(self.lChild != None):

return -1

self.lChild = BTNode(NewValue)

return 1

def AddRightChild (self, NewValue):

if(self.rChild != None):

return -1

self.rChild = BTNode(NewValue)

return 1

def GetLeftChild (self):

return self.lChild

def GetRightChild (self):

return self.rChild

class BinaryTree:

def __init__(self):

self.root = None

def CreateBinaryTree (ElementList):

#Implement this method and return appropriate value.

return None

def ExpandBinaryTree (self, NewElementList):

#Implement this method and return appropriate value.

return None

def TraverseInOrder(self):

#Implement this method and return appropriate value.

return None

def TraversePreOrder(self):

#Implement this method and return appropriate value.

return None

def TraversePostOrder(self):

#Implement this method and return appropriate value.

return None

-------------------------------------------------------------------------------------------------------------------------------------

Instructions to complete the above binary tree

-------------------------------------------------------------------------------------------------------------------------------------

of task1 stated below complete the code required for the task 2.

You are also expected to test and demonstrate your implementation using a

random binary search tree. You should complete the code and verify that

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Partially completed Binary Search Tree.

NOTE : BT_160000X.py is the completed code for the above binary tree code.

your code works using suitable test cases. In addition, you are required

import BT_160000X.py

class BSTree(BinaryTree): def __init__(self): super(self.__class__, self).__init__()

def AddValue (self, NewValue): #Implement this method and return appropriate value. return None

def DeleteValue (self, DelValue): #Implement this method and return appropriate value. return None

def SearchValue (self, SearchValue): #Implement this method and return appropriate value. return None

def PrintTree (self): #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 (NewValue) This function will add the value specified by NewValue to the binary search tree 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. def DeleteValue (DelValue) This function will delete the value specified by Value from the tree if the value is present in the tree. It returns the deleted element if deletion is successful and returns None in failure. def SearchValue (SearchValue) This function will return a pointer to the node which contains value specified by Value in the tree if the value is present in the tree. If the value is not in the tree, it will return None. void PrintTree) This function will print the values in the tree in sorted order

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!