Answered step by step
Verified Expert Solution
Question
1 Approved Answer
use python help me with this problem Question 2: Largest Subtree Total > For a treet = (t1, t2), the subtrees of t consist of
use python help me with this problem
Question 2: Largest Subtree Total > For a treet = (t1, t2), the subtrees of t consist of t, and of the subtrees of t and t2. That is, in formulas, subtrees(t) = {t} U subtrees(t) U subtrees(t2). To give a concrete example, the subtrees of t = (3,(4,5)) are: (3,(4,5)) 3 (4,5) .4 5 . Given a tree t, write a function max_subtree_total(t) that computes the largest total of any subtree in t. Of course, if the numbers in the tree are all non-negative, then the largest total corresponds to the complete tree, but this is not the case if there are leaves with value smaller than 0. For instance, for the tree (-2, (3, 4)) the largest total corresponds to the subtree (3, 4), which has total 7. If you wish, you can use the total function you developed in the previous question, but you don't have to. [104] def max_subtree_total (t): ### YOUR CODE HERE ### 5 points. Some simple cases first. check_equal (max_subtree_total(3), 3) check_equal (max_subtree_total((4, 5)), 9) Success Success ### 10 points. More complex cases. check_equal (max_subtree_total((-3, 4)), 4) check_equal (max_subtree_total((-3, -4)), -3) check_equal (max_subtree_total(((-3, 5), (2, 1))), 5) check_equal (max_subtree_total((((4, 5), -3), (12, (3, 4)))), 25)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