learngraphtheory.org

Interactive Graph Theory Learning

Guest User

Using app without sign in

Prepared byHadjoudj Mohammed IslamMaster's in Operations Research · Bachelor's in Mathematics

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.

Algorithm Selection
This algorithm requires a directed graph. Check Settings tab to configure.

Critical Path Calculator

Critical path calculator

Identifies the longest sequence of dependent tasks in a project schedule, determining the shortest time possible to complete the project.

Time: O(V + E)
Space: O(V)
Use Case: Project scheduling and bottleneck identification.
Algorithm Execution

Select an algorithm and generate steps to begin visualization

About Critical Path Method (CPM)

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.

How it works

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).

Applications

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.

Pseudocode

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 0

The 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.

Worked example, step by step

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.

  1. Forward pass, A and B. Neither has a predecessor, so both start at time 0. A finishes at 3, B finishes at 2. They run in parallel.
  2. Forward pass, C. C waits for both, so its earliest start is the maximum of 3 and 2, which is 3. It runs 4 days and finishes at 7. Note that B finished a day earlier and simply waits.
  3. Forward pass, D. D starts at 7 and finishes at 9. Nothing follows it, so the project duration is 9 days.
  4. Backward pass. Working back from 9: D must start by 7, so C must finish by 7 and start by 3. Both A and B must therefore finish by 3, giving A a latest start of 0 and B a latest start of 1.
  5. Compute slack. A has latest start 0 against earliest start 0, so slack 0. B has latest start 1 against earliest start 0, so slack 1. C and D both have slack 0.

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.

Complexity, and where it comes from

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.

When to use Critical Path Method (CPM), and when not to

CPM assumes durations are known and resources unlimited. Relaxing either assumption changes the problem.

AlternativePrefer it whenCost
PERTDurations are uncertain. Uses three-point estimates to give an expected duration and a probability distribution.O(V + E)
RCPSPResources are limited, so activities compete rather than running freely in parallel. NP-hard.exponential
Topological sortYou only need a valid execution order, not timings or float.O(V + E)
Longest path in a DAGThe same computation stated in graph terms. CPM is exactly this with activity durations as weights.O(V + E)
Crashing analysisYou want to shorten the project and need the cheapest set of activities to accelerate.linear programming

Common pitfalls

  • Taking the minimum instead of the maximum in the forward pass. An activity cannot start until every predecessor is done, so the earliest start is the maximum over predecessor finishes. Using the minimum produces a schedule that is impossibly short and quietly wrong.
  • Assuming the critical path is unique. Several paths can tie for longest, and then every activity on all of them has zero slack. Shortening just one does nothing, because the other critical path still governs the finish date.
  • Forgetting that the critical path moves. Shorten a critical activity enough and a different path becomes the longest. Crashing must be re-evaluated after each change rather than applied all at once from the original analysis.
  • Ignoring resource limits. CPM assumes A and B really can run at the same time. If both need the same machine or the same person, the schedule is fiction and you need RCPSP instead.
  • Running it on a network with a cycle. A circular dependency means no topological order exists and no schedule is valid. Detect the cycle and report it rather than producing numbers from a partial order.

Frequently asked questions

What is the critical path method?
CPM finds the longest path through a project network of activities and dependencies, which determines the shortest possible project duration. Activities on that path have zero slack, meaning any delay to them delays the entire project. It is computed with a forward pass for earliest times and a backward pass for latest times.
What is slack or float in CPM?
Slack is the amount of time an activity can be delayed without pushing back the project finish, calculated as latest start minus earliest start. Activities with zero slack are critical. In the worked example above, activity B has one day of slack while A, C and D have none.
What is the time complexity of the critical path method?
O(V + E), where V is the number of activities and E the number of dependencies. It is a topological sort followed by two linear sweeps over the network, so it scales easily to very large project plans.
What is the difference between CPM and PERT?
CPM uses a single deterministic duration per activity and focuses on identifying the critical path and float. PERT uses three estimates per activity, optimistic, most likely and pessimistic, to compute an expected duration and a variance, which lets you state the probability of finishing by a given date. The network analysis itself is the same.
Can the critical path change during a project?
Yes, and this is the main practical trap. If a critical activity is shortened or a non-critical one overruns its float, a different path can become the longest. The analysis must be rerun as actual durations become known rather than treated as fixed at planning time.

Related algorithms: PERT (Program Evaluation and Review Technique), RCPSP (Resource-Constrained Project Scheduling), Topological Sort

Interactive Controls
Basic Actions
• Double Click → Add Node
• Drag → Move Nodes
• Shift + Click → Connect Nodes
• Right Click → Context Menu
Advanced
• Ctrl + Click → Multi-Select
• Delete Key → Remove Selected
• Double Click Edge → Edit Weight
• Ctrl + Drag → Pan View

Zoom Controls

100%
Nodes: 4
Edges: 4