Data Structures & AlgorithmsHardGATE CS · ICPC regional

A directed acyclic graph has the vertices A, E, K, L, M, N and the directed edges L→A, K→N, E→K, L→E, M→N, L→K, M→E, E→N, L→N. How many edges does a longest directed path in this graph contain?

  1. A. 4
  2. B. 2
  3. C. 5
  4. D. 3

Correct answer: D. 3

Take dp[x] = 1 + max(dp[y]) over arcs y→x, with dp = 0 for sources; the largest dp value is 3 edges. Following the first listed out-arc at each step gives only 2, and counting vertices instead of edges gives 4.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic