Data Structures & AlgorithmsHardProduct-company placement

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

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

Correct answer: A. 3 paths, longest 3

Process vertices in reverse topological order: paths(u) = Σ paths(v) over edges u→v with paths(F) = 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