Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with my homework using Python; please DO NOT use classes in the code just use global or functions to do the task; thanks!

Please help with my homework using Python; please DO NOT use classes in the code just use global or functions to do the task; thanks!

the tree should look like this. I am very new to using 2d list at python so I am not sure how to manipulate it so if you could explain that would be much appreciated.

image text in transcribed

and here is the input

the list is a 2d array

g=[[1,2,3],

[2,4,5],

[4, 0, 0],

[5,0, 0],

[3,0,6],

[6,0,0]

]

The purpose is to find the height of the tree using recursion; please do not hard code the length of the tree but rather it should check which side is the longest and check the height of that side.

I appreciate your hard work and I promise to upvote it as long as it works and solves the problem.

thanks!

Here is the current code that I have from someone at chegg but it is incomplete, The code should have a build function to build or insert to the tree, and a function for getting the max. please test the code as well and output the desired output which is the height of the tree.

Please use the the 2d array input found on the top of this question.

here is a code base but this uses classes; do not use classes use global and functions

#code below

def maxheight(node): if node is None: return 0; else: if node. left==None and node.right==None: return max(maxheight(node.left), maxheight(node.right))+0 else: return max(maxheight(node.left), maxheight(node.right))+1
 
Node ID Computing the height of a binary tree: Our "dummy" tree structure: (PS: node 1 is the root node) Left Child ID Right Child ID means no LC) (means no RC) which means, given a data like this: 123 245 400 500 306 600 The tree should looks like 45 06 4 5 6 00 0 0 . Use the "Divide and Conquer idea" to write a program to find out the height of a binary tree. o The testing data can be found on course website

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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions

Question

Know how productivity improvements impact quality and value.

Answered: 1 week ago