Question: The code with the completed functions and the templates for incomplete functions are available You should complete the task and verify that your code works



The code with the completed functions and the templates for incomplete functions are available
You should complete the task and verify that your code works using suitable test cases.
In addition, you are required to demonstrate your code by creating a tree using some random numbers and then performing different operations on this tree.
The partially completed Binary Tree is as follows in Python language,

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
Task 1: Implementing a Binary Tree In the first task, you are given a partially completed implementation of a binary tree data structure using a single linked representation in Python. The representation uses a BTNode, which keeps links to its left and right child nodes. The BTNode has the capabilities to add a value as the left child or right child of the current node and to get the left and right child nodes of the current node. The BinaryTree is implemented using this BTNode and has an attribute called root which points to the root of the tree. The partially completed code for the binary tree is available in the BT_160000X.py file. Use it as the as the starting point and implement the binary tree by completing the given incomplete methods (listed below) def CreateBinaryTree (ElementList) Will create a binary tree which contains the list of elements in the array of elements in the ElementList in the same order. The tree will look like following if a list A of 10 elements is the input. The method should return the newly created tree
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
