Sub topic 8
Find the critical path
The forward pass from the previous chapter gave you the earliest start and finish for every task, and a project length of 26 days. This chapter explains which tasks decide that length. Those tasks form the critical path. Delaying any task on it delays the whole project.
This chapter assumes you can already:
- Read a task table with durations and finish-to-start dependencies.
- Run the forward pass.
- Read basic Python (dictionaries, loops, comprehensions).
What the critical path is
The critical path is the longest chain of dependent tasks from the project start to the project end. "Longest" means longest in total duration. That chain sets the earliest date the project can finish, because every task on it must wait for the one before it.
Two consequences follow:
- Shortening a task on the critical path shortens the project, up to a limit explained below.
- Shortening a task off the critical path changes nothing about the finish date.
The critical path says nothing about importance or difficulty. A trivial two-day task can be critical. A hard three-month task can be non-critical if it runs in parallel with something longer.
Find it by listing every path
For a small project you can find the critical path by hand. A path is any chain of tasks that follows the dependency arrows from a task with no predecessors to a task with no successors. Add up the durations on each path. The largest total is the critical path.
Here are the tasks from the forward-pass example:
| Task | Duration (days) | Predecessors |
|---|---|---|
| Wireframes | 5 | none |
| Mockups | 7 | Wireframes |
| Backend | 12 | Wireframes |
| Frontend | 10 | Mockups |
| Integration | 4 | Frontend, Backend |
The network has two paths from start to end:
| Path | Calculation | Total |
|---|---|---|
| Wireframes, Mockups, Frontend, Integration | 5 + 7 + 10 + 4 | 26 |
| Wireframes, Backend, Integration | 5 + 12 + 4 | 21 |
The first path is the longest, so it is the critical path. It matches the 26 days the forward pass produced. The two numbers must always agree. If they do not, one of the dependencies or durations has been misread.
Listing paths stops being practical once a project has dozens of tasks, because the number of paths grows quickly. The method below scales to any size.
Find it with a backward pass
The forward pass computes the earliest start and finish of each task. The backward pass computes the latest start and finish each task can have without delaying the project. It runs in the opposite direction.
- Set the project end to the largest earliest finish from the forward pass. Here that is 26.
- For each task with no successors, set its latest finish to the project end.
- For every other task, set its latest finish to the smallest latest start among its successors.
- For every task, set its latest start to its latest finish minus its duration.
- Work from the last task back to the first.
The rule in step 3 uses the minimum because a task must finish in time for its most demanding successor. Backend feeds only Integration, so its latest finish is Integration's latest start, which is 22. Wireframes feeds both Mockups and Backend, so it takes the smaller of their latest starts.
Slack (also called float) is the gap between the latest and earliest start:
slack = latest start − earliest start
Tasks with zero slack are the critical tasks. The critical path is the chain of zero-slack tasks that links the project start to the project end.
Worked calculation
Here are the results for the example project:
| Task | Earliest start | Earliest finish | Latest start | Latest finish | Slack |
|---|---|---|---|---|---|
| Wireframes | 0 | 5 | 0 | 5 | 0 |
| Mockups | 5 | 12 | 5 | 12 | 0 |
| Backend | 5 | 17 | 10 | 22 | 5 |
| Frontend | 12 | 22 | 12 | 22 | 0 |
| Integration | 22 | 26 | 22 | 26 | 0 |
Backend is the only task with slack. It can start as late as day 10 or run 5 days longer than planned, and Integration still starts on day 22. The next chapter on slack covers how to use that margin. Here we only need to know that zero slack marks a critical task.
Compute it in Python
The script below repeats the forward pass from earlier and adds the backward pass. It relies on the dictionary listing predecessors before successors, as the forward pass already does.
tasks = {
"Wireframes": (5, []),
"Mockups": (7, ["Wireframes"]),
"Backend": (12, ["Wireframes"]),
"Frontend": (10, ["Mockups"]),
"Integration": (4, ["Frontend", "Backend"]),
}
# Forward pass: earliest start and finish.
start, finish = {}, {}
for name, (duration, preds) in tasks.items():
start[name] = max((finish[p] for p in preds), default=0)
finish[name] = start[name] + duration
project_end = max(finish.values())
# Build the successor lists from the predecessor lists.
succs = {name: [] for name in tasks}
for name, (duration, preds) in tasks.items():
for p in preds:
succs[p].append(name)
# Backward pass: latest start and finish, last task first.
late_start, late_finish = {}, {}
for name in reversed(list(tasks)):
duration = tasks[name][0]
late_finish[name] = min(
(late_start[s] for s in succs[name]), default=project_end
)
late_start[name] = late_finish[name] - duration
slack = {name: late_start[name] - start[name] for name in tasks}
critical = [name for name in tasks if slack[name] == 0]
print(project_end) # 26
print(slack)
print(critical)The script prints:
26
{'Wireframes': 0, 'Mockups': 0, 'Backend': 5, 'Frontend': 0, 'Integration': 0}
['Wireframes', 'Mockups', 'Frontend', 'Integration']The default=project_end argument handles tasks with no successors. The default=0 in the forward pass does the same job for tasks with no predecessors.
Mark the critical path on the chart
In Mermaid, the crit tag colours a task as critical. Apply it to the zero-slack tasks you just found:
gantt
title Website Launch
dateFormat YYYY-MM-DD
section Design
Wireframes :crit, w, 2026-01-05, 5d
Mockups :crit, m, after w, 7d
section Build
Backend :b, after w, 12d
Frontend :crit, f, after m, 10d
Integration :crit, i, after f b, 4dTwo details matter here. The after f b syntax makes Integration wait for both predecessors, which is the same as the max in the forward pass. Also, Mermaid colours only the tasks you tag. It does not compute the critical path for you, so the tags go stale whenever durations or dependencies change.
Note that Mermaid counts calendar days unless you configure exclusions. If your real schedule skips weekends, the dates on the chart will not match a working-day calculation. The calendars chapter covers this.
Edge cases
Several critical paths
Two paths can have the same total length. Both are then critical, and a delay on either one delays the project. Suppose Backend took 17 days instead of 12. The Backend route would total 5 + 17 + 4 = 26, tying the Mockups and Frontend route. Backend's slack would drop to 0, and the script above would list it as critical. A project with several critical paths is riskier, because there are more tasks that can slip the end date.
Near-critical paths
A path with 1 or 2 days of slack is not formally critical, but a small delay turns it critical. Check the tasks with the smallest positive slack as well. In the original example, Backend has 5 days of slack, which is comfortable. A task with 1 day of slack is one bad estimate away from becoming critical.
A fixed deadline
So far the project end was the earliest possible finish. If a deadline is set, use it as the project end in the backward pass. Slack is then measured against the deadline:
- If the deadline is later than the earliest finish, every task gains the difference as extra slack, and the critical path has positive slack.
- If the deadline is earlier than the earliest finish, slack becomes negative. In the example, a deadline of day 24 gives the critical tasks a slack of −2. Negative slack means the plan cannot meet the date without changes.
The critical path moves
The critical path is a property of the current plan. Shorten the critical tasks and another path can become the longest. If you cut Frontend from 10 days to 4, the Mockups route totals 5 + 7 + 4 + 4 = 20, and the Backend route at 21 days becomes critical. Shortening the critical path only helps until a parallel path takes over. After each change, recompute.
Resource limits
The calculation assumes unlimited people. If the same person must do Backend and Frontend, those tasks cannot truly run in parallel, and the real schedule is longer than 26 days. Adding a dependency between them, or levelling the resources, changes the path. Standard critical path analysis does not detect this, so check resource conflicts yourself.
Invalid networks
A dependency loop (A needs B, B needs A) has no valid schedule. The forward pass fails on it, because a task's predecessor has no finish time yet. A dependency on a task that does not exist fails the same way. Fix the data before you calculate.
Use the critical path
Once you know the critical path, you can act on it:
- Watch critical tasks most closely. Report their status first.
- Assign your most reliable people to them.
- To finish earlier, shorten critical tasks. Add people, cut scope, or overlap them where the dependency allows it.
- To protect the date, add a buffer after the critical chain, not padding inside every task.
- Do not spend effort speeding up non-critical tasks. It buys no schedule gain.
Exercise
A project has tasks A (3 days, no predecessors), B (6 days, after A), C (2 days, after A), D (4 days, after B and C). What is the critical path, the project length, and the slack on C?
Show answer
The paths are A, B, D (3 + 6 + 4 = 13) and A, C, D (3 + 2 + 4 = 9). The critical path is A, B, D and the project is 13 days long. D starts on day 9 at the earliest, when B finishes. C can finish as late as day 9, and it can start as early as day 3 and as late as day 7. Its slack is 7 − 3 = 4 days.
Exercise
In the Python example, Backend is changed to 17 days. Which tasks does the script list as critical, and what is the project length?
Show answer
The Backend route totals 5 + 17 + 4 = 26, which ties the Mockups and Frontend route. Backend finishes on day 22, the same day as Frontend, so Backend's slack is 0. The project stays 26 days long, and the script lists all five tasks as critical: Wireframes, Mockups, Backend, Frontend and Integration.
Exercise
The deadline for the original example is day 24, not day 26. What is the slack on Wireframes, and what does it tell you?
Show answer
The backward pass now starts from 24, so Integration's latest start is 20 and Wireframes' latest start is −2. Its earliest start is 0, so its slack is −2. Negative slack means the plan is 2 days too long for the deadline. You must shorten the critical path by at least 2 days or move the deadline.