Question: COMPLETE #TODO PARTS Problem Complete the function makeTree() to take in a height, and create a tree with the given height. The tree must have

COMPLETE #TODO PARTS

Problem

Complete the function makeTree() to take in a height, and create a tree with the given height. The tree must have (2^height) - 1 nodes. Each node's value should be (height - level + 1). In other words, if we ask for a tree of height 3, the root node will have value 3, its two children will have value 2, and their four children will have value 1.

Example

 
 

root = makeTree(3) # should return the root node of a tree

 

# that looks like this:

 COMPLETE #TODO PARTS Problem Complete the function makeTree() to take inCode:

class Node: def __init__(self, value): self.value = value self.left = None self.right = None def makeTree(height): # TODO

# do not modify, this is function given to help you solve this: def printTree(root): if root is not None: printTree(root.left) print(root.value) printTree(root.right) # example root = makeTree(3) printTree(root) # should print 1 2 1 3 1 2 1

1 class Node: 2 def __init_(self, value): Problem self.valuevalue self.left None self.right None Complete the function makeTree() to take in a height, and create a tree with the given height. The tree must have (2Aheight) - 1 nodes. Each node's value should be (height - level 1). In other words, if we ask for a tree of height 3, the root node will have value 3, its two children will have value 2, and their four children will have value1 7 def makeTree(height): # TODO Example 10 # do not modify, this is function given to help you solve this: 11- def printTreeCroot): 12 if root is not None: 13 14 15 16 17 18 # example 19 root - makeTree(3) 20 printTree(root) # should print 1 2 1 3 1 2 1 21 root-makeTree (3) tree should return the root node of a # that looks like this: printTree(root.left) print(root.value) printTree(root.right)

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!