Data Structures & AlgorithmsHardGATE CS
In the DAG with edges A→C, A→F, A→G, B→A, B→C, B→G, E→C, E→D, F→E, F→G, G→D, how many distinct directed paths are there from B to D, and how many edges does the longest one have?
- A. 4 paths, longest 3
- B. 5 paths, longest 4
- C. 3 paths, longest 4
- D. 4 paths, longest 4
Correct answer: D. 4 paths, longest 4
Process vertices in reverse topological order: paths(u) = Σ paths(v) over edges u→v with paths(D) = 1, giving 4; the same order with max(1 + len(v)) gives the longest path, 4 edges.
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
- Five matrices have dimensions 10×15 , 15×3 , 3×5 , 5×15 , 15×15. What is the minimum number of scalar multiplications needed to compute…
- What is the minimum number of edges that must be deleted from the undirected graph with edges A–B, A–D, A–E, B–E, B–F, C–D, C–F, D–E, E–F…
- A 4-ary max-heap is stored in a 0-indexed array (children of i at 4i + 1 … 4i + 4): [51, 46, 36, 39, 2, 22, 35, 14, 13, 24]. After…
- How many subsets of {4, 7, 9, 10, 11, 13, 14} have sum exactly 31?
- Unit-time jobs (deadline, profit): J1 (3, 45), J2 (2, 47), J3 (1, 77), J4 (1, 75), J5 (1, 13), J6 (2, 37), J7 (3, 59). One job runs at a…
- A directed graph on A–H has edges B→A, B→C, C→F, C→H, D→C, E→C, E→H, F→G, F→H, G→C, H→A. How many strongly connected components does it…