Question
# A Node is an object # - value : Number # - children : List of Nodes class Node: def __init__(self, value, children): self.value
# A Node is an object
# - value : Number # - children : List of Nodes class Node: def __init__(self, value, children): self.value = value self.children = children
exampleTree = Node(1,[Node(2,[]),Node(3,[Node(4,[Node(5,[]),Node(6,[Node(7,[])])])])])
# Objectives: # (1) Write a function to calculate the sum of every node in a tree (iteratively)
def sumNodes(root): pass
# (2) Write a function to calculate the sum of every node in a tree (recursively)
def sumNodesRec(root): pass
################################# # Objectives: # (1) Write a function compose, which takes an inner and outer function # and returns a new function applying the inner then the outer function to a value
def compose(f_outer, f_inner): pass
################################# # Bonus ################################# # Objectives: # (1) Create a string which has each level of the tree on a new line
def treeToString(root): pass
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started