Data Structures & AlgorithmsHardGATE CS

In the DAG with edges B→E, C→A, C→G, D→A, D→B, D→C, D→F, D→G, F→A, F→B, F→C, how many distinct directed paths are there from D to G, and how many edges does the longest one have?

  1. A. 3 paths, longest 2
  2. B. 3 paths, longest 3
  3. C. 4 paths, longest 3
  4. D. 5 paths, longest 3

Correct answer: B. 3 paths, longest 3

Process vertices in reverse topological order: paths(u) = Σ paths(v) over edges u→v with paths(G) = 1, giving 3; the same order with max(1 + len(v)) gives the longest path, 3 edges.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic