Recall & Review
beginner
What is the Maximum Path Sum in a binary tree?
It is the largest sum of node values obtained by any path in the tree. The path can start and end at any nodes, but must follow parent-child connections.
Click to reveal answer
beginner
In the Maximum Path Sum problem, must the path go through the root?
No. The path can start and end at any nodes in the tree, not necessarily including the root.
Click to reveal answer
intermediate
Why do we use a helper function that returns the maximum gain from a node in the Maximum Path Sum problem?
Because we want to find the best path sum that can be extended upwards to the parent. The helper returns the maximum sum of a path starting at the current node and going down one side.
Click to reveal answer
intermediate
What does it mean if the maximum gain from a child node is negative in the Maximum Path Sum problem?
We ignore that child's path by taking zero instead, because adding a negative sum would reduce the total path sum.
Click to reveal answer
intermediate
How do we update the global maximum path sum during recursion in the Maximum Path Sum problem?
At each node, we consider the sum of the node's value plus maximum gains from left and right children. If this sum is greater than the current global maximum, we update it.
Click to reveal answer
In the Maximum Path Sum problem, what does the helper function return?
✗ Incorrect
The helper returns the maximum gain from the current node to one child path, which can be extended upwards.
If a child node's maximum gain is negative, what should we do?
✗ Incorrect
Negative gains reduce the path sum, so we ignore them by taking zero.
Can the maximum path sum path pass through the root node?
✗ Incorrect
The path can pass through the root if it yields the maximum sum, but it is not required.
What is the time complexity of the Maximum Path Sum algorithm using recursion?
✗ Incorrect
Each node is visited once, so the time complexity is O(n), where n is the number of nodes.
What does the global variable track in the Maximum Path Sum problem?
✗ Incorrect
The global variable keeps track of the maximum path sum found anywhere in the tree.
Explain how recursion helps find the Maximum Path Sum in a binary tree.
Think about how each node contributes to the path sum and how you combine left and right child results.
You got /4 concepts.
Describe the difference between the maximum gain returned by the helper and the global maximum path sum.
One is local to a node's single path, the other is overall best path.
You got /4 concepts.