Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional
A binary tree has these nodes: node 2 (value -7): left none, right none; node 9 (value 7): left 34, right 39; node 34 (value -5): left 80, right none; node 39 (value -7): left 93, right none; node 44 (value 9): left none, right none; node 45 (value 2): left none, right none; node 69 (value -4): left 89, right 9; node 80 (value 7): left none, right 2; node 83 (value 9): left none, right 45; node 89 (value -7): left none, right none; node 93 (value -6): left none, right 44; node 96 (value -9): left 83, right 69. 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. 2
- B. 11
- C. 9
- D. 7
Correct answer: B. 11
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 4 (value 9): left 67, right 54; node 8 (value 1): left none, right 11; node 11 (value 9): left none…
- A binary tree has these nodes: node 3 (value -7): left none, right none; node 8 (value -7): left 49, right none; node 16 (value 2): left…
- Elements 0 to 8 start as 9 separate singleton sets. The calls union(7, 1), union(5, 2), union(4, 5), union(0, 6), union(0, 2), union(4…
- Elements 0 to 5 start as 6 separate singleton sets. The calls union(3, 0), union(1, 4), union(4, 0), union(5, 5), union(4, 1), union(2…
- Elements 0 to 7 start as 8 separate singleton sets. The calls union(1, 4), union(3, 5), union(1, 3), union(1, 2), union(3, 6), union(6…
- Elements 0 to 7 start as 8 separate singleton sets. The calls union(1, 4), union(7, 1), union(5, 3), union(0, 4), union(4, 1), union(2…