Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# 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

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_2

Step: 3

blur-text-image_3

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

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

Explain the key areas in which service employees need training.

Answered: 1 week ago

Question

Understand the role of internal marketing and communications.

Answered: 1 week ago