Data Structures & AlgorithmsHardProduct-company placement

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

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

Correct answer: C. 6 paths, longest 3

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