140 likes | 824 Views
Longest Path in a DAG. Algorithm. Compute topological order of vertices: A B C D E F G H I . F. D. 3. 6. E. time. 5. C. H. I. A. B. G. 0. 6. 0. 4. 2. 4. Longest Path in a DAG. Algorithm. Compute topological order of vertices: A B C D E F G H I .
E N D
Longest Path in a DAG • Algorithm. • Compute topological order of vertices: A B C D E F G H I. F D 3 6 E time 5 C H I A B G 0 6 0 4 2 4
Longest Path in a DAG • Algorithm. • Compute topological order of vertices: A B C D E F G H I. • Initialize fin[v]= 0 for all vertices v. 0 earliest finish time 0 F D 3 0 6 E 5 0 0 0 0 0 0 C H I A B G 0 6 0 4 2 4
4 X Longest Path in a DAG • Algorithm. • Compute topological order of vertices: A B C D E F G H I. • Initialize fin[v]= 0 for all vertices v. • Consider vertices v in topological order: • for each edge v-w, set fin[w] = max(fin[w], fin[v] + time[w]) 0 0 F D 3 0 6 E 5 0 0 0 0 0 0 C H I A B G 0 6 0 4 2 4
10 X 6 4 X X Longest Path in a DAG • Algorithm. • Compute topological order of vertices: A B C D E F G H I. • Initialize fin[v]= 0 for all vertices v. • Consider vertices v in topological order: • for each edge v-w, set fin[w] = max(fin[w], fin[v] + time[w]) 0 0 F D 3 0 6 E 5 0 0 0 0 0 0 C H I A B G 0 6 0 4 2 4
12 10 10 X X X 6 4 X X Longest Path in a DAG • Algorithm. • Compute topological order of vertices: A B C D E F G H I. • Initialize fin[v]= 0 for all vertices v. • Consider vertices v in topological order: • for each edge v-w, set fin[w] = max(fin[w], fin[v] + time[w]) 0 0 F D 3 0 6 E 5 0 0 0 0 0 0 C H I A B G 0 6 0 4 2 4
12 13 15 10 10 X X X X X 4 6 X X Longest Path in a DAG • Algorithm. • Compute topological order of vertices: A B C D E F G H I. • Initialize fin[v]= 0 for all vertices v. • Consider vertices v in topological order: • for each edge v-w, set fin[w] = max(fin[w], fin[v] + time[w]) 0 0 F D 3 0 6 E 5 0 0 0 0 0 0 C H I A B G 0 6 0 4 2 4
10 13 15 12 10 X X X X X X X 6 4 19 21 X X Longest Path in a DAG • Algorithm. • Compute topological order of vertices: A B C D E F G H I. • Initialize fin[v]= 0 for all vertices v. • Consider vertices v in topological order: • for each edge v-w, set fin[w] = max(fin[w], fin[v] + time[w]) 0 0 F D 3 0 6 E 5 0 0 0 0 0 0 C H I A B G 0 6 0 4 2 4
13 10 10 15 13 12 X X X X X X X X 6 4 19 21 X X Longest Path in a DAG • Algorithm. • Compute topological order of vertices: A B C D E F G H I. • Initialize fin[v]= 0 for all vertices v. • Consider vertices v in topological order: • for each edge v-w, set fin[w] = max(fin[w], fin[v] + time[w]) 0 0 F D 3 0 6 E 5 0 0 0 0 0 0 C H I A B G 0 6 0 4 2 4
13 10 10 13 15 12 X X X X X X X X X 6 4 19 21 25 X X Longest Path in a DAG • Algorithm. • Compute topological order of vertices: A B C D E F G H I. • Initialize fin[v]= 0 for all vertices v. • Consider vertices v in topological order: • for each edge v-w, set fin[w] = max(fin[w], fin[v] + time[w]) 0 0 F D 3 0 6 E 5 0 0 0 0 0 0 C H I A B G 0 6 0 4 2 4
15 10 13 10 12 13 X X X X X X X X X X 6 4 19 21 25 25 X X Longest Path in a DAG • Algorithm. • Compute topological order of vertices: A B C D E F G H I. • Initialize fin[v]= 0 for all vertices v. • Consider vertices v in topological order: • for each edge v-w, set fin[w] = max(fin[w], fin[v] + time[w]) 0 0 F D 3 0 6 E 5 0 0 0 0 0 0 C H I A B G 0 6 0 4 2 4
15 10 13 10 12 13 X X X X X X X X X X 6 4 19 21 25 25 X X Longest Path in a DAG • Algorithm. • Compute topological order of vertices: A B C D E F G H I. • Initialize fin[v]= 0 for all vertices v. • Consider vertices v in topological order: • for each edge v-w, set fin[w] = max(fin[w], fin[v] + time[w]) 0 0 F D 3 0 6 E 5 0 0 0 0 0 0 C H I A B G 0 6 0 4 2 4
Longest Path in a DAG • Algorithm. • Compute topological order of vertices: A B C D E F G H I. • Initialize fin[v]= 0 for all vertices v. • Consider vertices v in topological order: • for each edge v-w, set fin[w] = max(fin[w], fin[v] + time[w]) 13 10 F D 3 15 6 E critical path 5 0 19 6 25 25 4 C H I A B G 0 6 0 4 2 4