Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 1 : Given a binary tree and an integer targetSum, return true if the tree has a root - to - leaf path such
Question : Given a binary tree and an integer targetSum, return true if the tree has a
roottoleaf path such that adding up all the values along the path equals targetSum.
Note: A leaf is a node with no children.
Return false if there does not exist a roottoleft path that adds up to the targetSum.
Find the appropriate search strategy that was discussed in the class heuristic DFS BFS
etc to traverse the input tree for the above problem statement.
Identify all the edge cases. such as if the tree node is NULL or reached to the end of the
tree.
Explain the intuition behind why your search strategy is better than the other strategies
that we discussed in class.
Highlight the roottoleaf path that you achieved from your strategy.
Evaluate your strategysolution based upon the dimensions discussed in the class.
a Completeness
b Time and space complexity
c Optimality
Submit a PDF copy of your solution.
An example that outputs TRUE for the problem statement:
Given the following tree and targetSum your search algorithm should return TRUE.
Explanation:
The path gives us the target sum Hence, the algorithm returns true.
An example that outputs FALSE for the problem statement:
Given the following tree and targetSum your search algorithm should return FALSE.
Explanation: The path sums up to The path sums up to The path or
sums up to Hence, in no way we can get target sum So the algorithm returns
false.
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