[DP5] Longest path in an ordered graph (3 pts) [00QT]
Let G = (V,E) be a directed, unweighted graph with nodes v_1, \dots , v_n. We say that G is an ordered graph if it has the following properties:
- 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 (v_i, v_j) with i < j.
- Every node other than v_n has at least one outgoing edge.
Given an ordered graph G, we want to find the longest path from v_1 to v_n.
Consider the following greedy algorithm.
Show that this algorithm does not correctly solve the problem, by giving an example of an ordered graph for which it does not return the correct answer. Be sure to explain what the correct answer is and what incorrect answer is returned by the algorithm.w \gets v_1L \gets 0\mathsf {while} w \neq v_n:Choose the outgoing edge (w, v_j) with the smallest jw \gets v_jIncrement L\mathsf {return} L- Describe an efficient algorithm that takes an ordered graph G and returns the length of the longest path from v_1 to v_n. Justify its correctness and analyze its time complexity.