Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional
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 none, right none; node 46 (value -6): left none, right none; node 70 (value 8): left none, right 44; node 81 (value 0): left 88, right 99; node 88 (value -6): left none, right 6; node 99 (value -7): left 46, right 70. 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. 12
- B. 5
- C. 8
- D. 6
Correct answer: A. 12
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 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…
- A binary tree has these nodes: node 12 (value 9): left 17, right 66; node 17 (value 0): left 69, right none; node 48 (value -6): left…
- A binary tree has these nodes: node 6 (value -7): left none, right none; node 11 (value -3): left none, right none; node 30 (value -7)…
- A binary tree has these nodes: node 5 (value -6): left none, right 6; node 6 (value 5): left 33, right none; node 21 (value 8): left 5…
- A binary tree has these nodes: node 23 (value 6): left 68, right 38; node 24 (value 2): left 64, right 62; node 25 (value 9): left none…