Question: Let G = (V, E) be a directed graph with nodes v 1 , . . . , v n . We say that G
Let G = (V, E) be a directed graph with nodes v 1 , . . . , v n . 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 (v i , v j ) with i < j. (ii) Each node except v n has at least one edge leaving it. That is, for every node v i , i = 1,2, . . . ,n 1, there is at least one edge of the form (v i ,v j ). 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 6.29 for an exam- ple). Given an ordered graph G, find the length of the longest path that begins at v 1 and ends at v n . (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. Set w = v 1 Set L = 0 v 3 v 4 v 5 v 1 v 2 Figure 6.29 The correct answer for this ordered graph is 3: The longest path from v 1 to v n uses the three edges (v 1 , v 2 ),(v 2 , v 4 ), and (v 4 , v 5 ). While there is an edge out of the node w Choose the edge (w, v j ) for which j is as small as possible Set w = v j Increase L by 1 end while Return L as the length of the longest path 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 v 1 and ends at v n . (Again, the length of a path is the number of edges in the path.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
