Data Structures & AlgorithmsHardProduct-company placement

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

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

Correct answer: C. 6 paths, longest 5

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic