Question: please do the first picture And here is Problem3 Objective: Suppose you are given a tree. Write a function treeToString(root) which constructs a string with

please do the first picture

please do the first picture And here is Problem3 Objective: Suppose you

And here is Problem3

are given a tree. Write a function treeToString(root) which constructs a string

Objective: Suppose you are given a tree. Write a function treeToString(root) which constructs a string with the values at each level of the tree on a new line. For example, using exTree from Problem 3. we would see the following: print(treeToString(exfree)) > > 23 2 40 > 56 > 7 Objects in Python are useful for many things. One common reason you might write a Python class is to build a custom data structure. For example, the following class defines a tree. # A Node is an object # value: Number # children : List of Nodes class Node : def __init__(self, value, children): self .value = value self. children = children Here's an example of creating a tree object: exTree = Node (1,1 Node (2,[]), Node (3, [ Node (4, [Node (5, []), Node (6, [ Node (7,0))))))))))) This is how exTree looks when drawn. 1 2 3 4 5 6 1 7 Objective: Complete the recSumNodes (root) function so it returns the sum of the values at each node in the tree using recursion. For example, recSumNodes (exTree) will return 28

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!