Data Structures & AlgorithmsModerateGATE CS · ICPC regional
A tree has vertices with values in brackets: M[0], R[5], A[9], G[-4], H[9]. The edges are M–R, M–A, R–G, M–H. A path is any sequence of adjacent vertices with no repeated vertex (a single vertex is a path). What is the maximum possible sum of values along one path?
- A. 9
- B. 19
- C. 18
- D. 23
Correct answer: C. 18
A DP that combines the two best downward chains at each vertex finds 18. Paths restricted to a single ancestor-to-descendant line give at most 9, and paths that start at the root give 9.
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
- Bellman–Ford is run from source P on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: Z→S…
- A directed graph has the vertices F, J, N, P, R, Z and the arcs P→F, P→Z, P→N, J→N, R→P, F→P, F→R, Z→P, Z→N, N→F, N→Z. How many strongly…
- Grid with 4 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: ...G .GGG GG.G G... Each step, which is a…
- A connected undirected graph has the vertices A, B, E, J, M and weighted edges (weights in brackets): M–E (8), A–E (17), M–B (10), A–B…
- An undirected graph has the vertices B, D, O, Q, T, X and the edges D–Q, X–D, B–D, X–Q, O–D, X–T, B–Q, D–T, X–O. What is the minimum…
- A directed acyclic graph has the vertices A, E, F, J, L, N and the arcs F→N, F→E, F→J, F→A, L→E, N→E, E→A, J→A. Two players alternately…