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

And here is Problem3

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
Get step-by-step solutions from verified subject matter experts
