PERT - Cs.princeton.edu

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
A
B
C
G
H
I
0
4
2
4
6
0
1
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.
earliest finish time
0
0
F
D
0
6
3
E
5
0
0
0
0
0
0
A
B
C
G
H
I
0
4
2
4
6
0
2
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
0
6
3
E
5
0
4
0
X
0
0
0
0
A
B
C
G
H
I
0
4
2
4
6
0
3
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])
10
0
X
0
F
D
0
6
3
E
0
4
0
X
6
X
0
5
0
0
0
A
B
C
G
H
I
0
4
2
4
6
0
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])
10
0
X
0
F
D
0
6
3
E
0
4
0
X
6
X
0
5
10
0
X
12
0
X
0
A
B
C
G
H
I
0
4
2
4
6
0
5
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
0
X
10
0
X
F
D
15
0
X
6
3
E
0
4
0
X
6
X
0
5
10
0
X
12
0
X
0
A
B
C
G
H
I
0
4
2
4
6
0
6
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
0
X
10
0
X
F
D
15
0
X
6
3
E
0
4
0
X
6
X
0
5
10
X
19
0
X
12
X
21
0
X
0
A
B
C
G
H
I
0
4
2
4
6
0
7
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
0
X
10
0
X
F
D
15
0
X
6
3
E
0
4
0
X
6
X
0
5
10
X
19
0
X
12
X
21
0
X
13
0
X
A
B
C
G
H
I
0
4
2
4
6
0
8
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
0
X
10
0
X
F
D
15
0
X
6
3
E
0
4
0
X
6
X
0
5
10
X
19
0
X
12
X
21
X
25
0
X
13
0
X
A
B
C
G
H
I
0
4
2
4
6
0
9
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
0
X
10
0
X
F
D
15
0
X
6
3
E
0
4
0
X
6
X
0
5
10
X
19
0
X
12
X
21
X
25
0
X
13
X
25
0
X
A
B
C
G
H
I
0
4
2
4
6
0
10
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
0
X
10
0
X
F
D
15
0
X
6
3
E
0
4
0
X
6
X
0
5
10
X
19
0
X
12
X
21
X
25
0
X
13
X
25
0
X
A
B
C
G
H
I
0
4
2
4
6
0
11
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
15
6
E
critical path
0
4
3
5
6
19
25
25
A
B
C
G
H
I
0
4
2
4
6
0
12