Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

image text in transcribed

image text in transcribed

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.

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions

Question

What is the test for whether a hypothesis is scientific or not?

Answered: 1 week ago