Question: Use the Python programming language only. Partially completed binary is available as follows You should complete the task and verify that your code works using

Use the Python programming language only.

Use the Python programming language only. Partially completed binary is available as

follows You should complete the task and verify that your code works

using suitable test cases. In addition, you're required to demastrate your code

Partially completed binary is available as follows

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

In addition, you're required to demastrate your code by creating a tree using some random numbers and then performing diffenrent operations on the tree.

by creating a tree using some random numbers and then performing diffenrent

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 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. Two methods "AddLeftchild (ParentNode, ChildValue) "and "AddRightChild (ParentNode, ChildValue)" are implemented to add the value specified by "ChildValue" as the left and right child nodes (respectively) of the BTNode specified by the "ParentNode". The two methods "GetLeftChild (Node)" and "GetRightChild (Node)" return the left and right child (respectively) of the BTNode specified by "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 "PBT_150000X.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

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!