Data Structures & AlgorithmsModerateCodeforces Div2 D · ICPC regional
A binary tree has these nodes: node 1 (value -5): left 30, right 56; node 10 (value -1): left none, right none; node 20 (value 5): left none, right none; node 27 (value 1): left none, right none; node 30 (value 8): left none, right 27; node 56 (value 5): left none, right 10; node 83 (value -2): left 1, right 20. A path is any sequence of nodes in which consecutive nodes are joined by an edge, with no node repeated; a single node is a path. The value of a path is the sum of its node values. What is the maximum value of any path?
- A. 9
- B. 3
- C. 8
- D. 7
Correct answer: A. 9
The best path may bend at any node, start and end anywhere, and can be a single node. Restricting it to start at the root, to be one node, or to pass through the root gives smaller values.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A binary tree has these nodes: node 3 (value -9): left 93, right 63; node 8 (value 5): left none, right 99; node 47 (value 2): left none…
- A binary tree has these nodes: node 19 (value -8): left 62, right 73; node 44 (value 3): left 56, right none; node 56 (value 7): left…
- A binary tree has these nodes: node 6 (value -6): left none, right none; node 23 (value -4): left 89, right none; node 29 (value 0): left…
- A binary tree has these nodes: node 6 (value 1): left none, right 7; node 7 (value 6): left none, right none; node 44 (value 4): left…
- A binary tree has these nodes: node 17 (value -6): left 39, right 29; node 29 (value 8): left none, right 91; node 39 (value -5): left 49…
- A binary tree has these nodes: node 14 (value 4): left none, right none; node 23 (value 7): left 66, right 58; node 31 (value -1): left…