389. Critical Path Method (CPM)
What’s the shortest possible time to finish the whole project, and which tasks are “tight” (any delay on them delays the whole project)
Let be a DAG with a duration of on each node. And edge means must finish before starts. and for in- and out-neighbors.
Forward Pass (one recurrence)
with (sources get ).
The makespan is .
Backward Pass (dual recurrence)
with (sinks get pinned to project end)
Clack & Critical Pass
Example
Let’s compute. We start the project at time 0.
- A has no predecessors, so ES = 0, and EF = 0 + 3 = 3.
- B depends only on A, so ES = EF(A) = 3, and EF = 3 + 4 = 7.
- C also depends only on A, so ES = EF(A) = 3, and EF = 3 + 2 = 5.
- D depends only on B, so ES = EF(B) = 7, and EF = 7 + 5 = 12.
- E depends only on C, so ES = EF(C) = 5, and EF = 5 + 1 = 6.