Interactive Graph Theory Learning
Interactive Graph Theory Learning
Guest User
Using app without sign in
Graph theory study guides
Instant download · Lifetime access
Prefer one-on-one help?
Private sessions on Critical Path Method (CPM) for your course, an interview or an optimization project.
Critical path calculator
Identifies the longest sequence of dependent tasks in a project schedule, determining the shortest time possible to complete the project.
Select an algorithm and generate steps to begin visualization
The Critical Path Method (CPM) finds the longest chain of dependent activities in a project network, which determines the minimum project duration. Activities on this critical path have zero slack: any delay in them delays the whole project.
The project is modeled as a directed acyclic graph of activities with durations. A forward pass in topological order computes the earliest start and finish of each activity; a backward pass computes the latest times that avoid delaying the project. The difference between latest and earliest start is the activity's float, and activities with zero float form the critical path. Both passes run in O(V + E).
CPM schedules construction projects, software releases, manufacturing changeovers, and event planning. Project management tools such as Primavera and Microsoft Project compute critical paths continuously. It is also a textbook application of longest paths in DAGs and topological sorting.
Two sweeps over the activity network in topological order: forward for the earliest each task can happen, backward for the latest it can happen without delaying the project.
CPM(activities, dependencies):
order = topologicalSort(activities)
// Forward pass: earliest start and finish
for each activity a in order:
ES[a] = max(EF[p] for p in predecessors(a)), or 0
EF[a] = ES[a] + duration[a]
T = max(EF[a] for all a) // project duration
// Backward pass: latest start and finish
for each activity a in reverse(order):
LF[a] = min(LS[s] for s in successors(a)), or T
LS[a] = LF[a] - duration[a]
slack[a] = LS[a] - ES[a]
critical path = activities with slack 0The critical path is the longest path through the network, not the shortest, which is what makes this a maximisation problem on a DAG rather than a shortest-path one. Because the network is acyclic, both sweeps are just dynamic programming in topological order and no priority queue is needed. Slack of zero means the activity has nowhere to move: delay it by a day and the whole project slips by a day.
Schedule a four-activity project where two tasks can run in parallel but both must finish before the third begins.
Example graph: Activities with durations A (3 days), B (2 days), C (4 days) and D (2 days). Dependencies: A and B must both precede C, and C precedes D.
The project takes 9 days and the critical path is A to C to D. B has one day of float, meaning it can start a day late or overrun by a day without affecting the finish date. This is the practical payoff: it tells a manager exactly where to concentrate attention. Shortening B is worthless, while shortening any of A, C or D shortens the whole project, at least until the critical path shifts to run through B instead.
Time: O(V + E) · Space: O(V)
A topological sort costs O(V + E), and each of the two sweeps visits every activity once and every dependency edge once, so both are O(V + E) as well. Space is four numbers per activity, the earliest and latest start and finish, so O(V). The whole method is linear, which is why it scales to project networks with hundreds of thousands of activities. The dependency network must be a directed acyclic graph: a circular dependency has no topological order, and correspondingly no valid schedule, so cycle detection is a genuine prerequisite rather than a formality.
CPM assumes durations are known and resources unlimited. Relaxing either assumption changes the problem.
| Alternative | Prefer it when | Cost |
|---|---|---|
| PERT | Durations are uncertain. Uses three-point estimates to give an expected duration and a probability distribution. | O(V + E) |
| RCPSP | Resources are limited, so activities compete rather than running freely in parallel. NP-hard. | exponential |
| Topological sort | You only need a valid execution order, not timings or float. | O(V + E) |
| Longest path in a DAG | The same computation stated in graph terms. CPM is exactly this with activity durations as weights. | O(V + E) |
| Crashing analysis | You want to shorten the project and need the cheapest set of activities to accelerate. | linear programming |
Related algorithms: PERT (Program Evaluation and Review Technique), RCPSP (Resource-Constrained Project Scheduling), Topological Sort