Question: Question 7 ) You are given a string representing a binary tree where each node is either ' 0 ' or ' 1 ' .

Question 7) You are given a string representing a binary tree where each node is either '0' or '1'. The
root of the tree is at index 0. Write a dynamic programming algorithm to find the maximum path sum
in the binary tree, where a path is defined as any sequence of nodes from some starting node to any
node in the tree along the parent-child connections. Note that the path can start and end at any node
in the tree. (10 points)
Hint: In Min Heap, we saw how to represent a tree using an array (a string in this question).
Examples:
max_path_sum("1010010") # Output: 3
(as the maximum path sum is obtained by the path: 1(root)->1->1(leaf))
Other paths have a smaller sum value.
 Question 7) You are given a string representing a binary tree

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!