Let G = (V, E) be a directed graph with nodes v1,…,vn. We say that G is an ordered graph if it has the following properties.
(i) Each edge goes from a node with a lower index to a node with a higher index. That is, every directed edge has the form (vi, vj) with i
(ii) Each node except vn has at least one edge leaving it. That is, for every node vi, i = 1,2,…,n – 1, there is at least one edge of the form (vi, vj).
The length of a path is the number of edges in it. The goal in this question is to solve the following problem (see Figure 1 for an example).
Given an ordered graph G, find the length of the longest path that begins at v1 and ends at vn.
(a) Show that the following algorithm does not correctly solve this problem, by giving an example of an ordered graph on which it does not return the correct answer.
![]()

In your example, say what the correct answer is and also what the algorithm above finds.
(b) Give an efficient algorithm that takes an ordered graph G and returns the length of the longest path that begins at v1 and ends at vn. (Again, the length of a path is the number of edges in the path.)
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.