Two different jobs are covered here. The first is finding the best route through a network — the cheapest, shortest or quickest way from one point to another. The second is planning a project made up of jobs that depend on each other, and working out which chain of jobs decides how long the whole project takes. Both are done with weighted networks, but they ask opposite questions: the best route is usually the shortest path, while the chain that fixes the project length is the longest path. For shortest paths, we use Dijkstra's algorithm and Bellman's Principle of Optimality across multi-stage routing, stock control, resource allocation, and equipment replacement. For project scheduling, we draw activity networks, find early and late times using forward and backward passes, calculate total float, and identify critical paths.
Networks, Terminology, and What 'Optimal' Means
A network (or graph) is a collection of vertices (or nodes) joined by edges (or arcs). In an undirected network, edges can be traversed in both directions. In a directed network, edges are arrows indicating one-way movement. A path is an unbroken sequence of edges connecting a sequence of vertices without repeating any vertex.
A cycle is a closed path that starts and finishes at the same vertex without repeating any edge. A network containing no cycles is described as acyclic. A graph is connected if there is at least one path between every pair of vertices. If some vertices cannot be reached from the rest, the network is disconnected. Dijkstra's algorithm only computes distances to nodes within the same connected component as the source.
Every edge carries a numerical weight, representing a physical metric such as distance, travel time, financial cost, or capacity. Depending on the scenario, optimal has different meanings:
- In routing problems, optimal typically means finding a shortest path to minimise total travel time, distance, or cost.
- In project scheduling, optimal refers to determining the minimum project completion time by identifying the critical path, which is the longest-duration path of dependent tasks through the network.
Comparing Shortest-Route Techniques
The Leaving Certificate syllabus requires evaluating different techniques for finding shortest routes:
- Exhaustive search (listing every path): Guarantees finding the global optimum for small networks, but the number of potential paths grows exponentially as nodes increase, making it impractical for large networks.
- Dijkstra's algorithm: Very efficient and determines the shortest route from the source to every node in a single sweep. It requires all edge weights to be non-negative ().
- Bellman's dynamic programming: Ideal for problems structured into sequential stages (such as inventory periods or project years). It handles non-edge costs and negative values, and provides the optimal continuation from every intermediate state.
Dijkstra's Shortest Path Algorithm
Dijkstra's algorithm is a greedy algorithm that determines the shortest path from a single source vertex to all other vertices in a weighted network where all edge weights are non-negative (). If negative weights are present, Dijkstra's algorithm can fail because a subsequent negative edge could make an already settled path shorter.
Recording Your Work Clearly
Most marks in a Dijkstra question are awarded for your working method. You must keep track of three values at every node:
- Order of labelling: The sequence number in which the vertex is permanently settled (beginning with 1 at the source).
- Final value: The confirmed shortest cumulative distance from the source.
- Working values: Provisional distances calculated from adjacent permanently labelled nodes. When a smaller working value is found, cross out the old value neatly and record the new one beside it, noting the predecessor node.
A clear way to show this at each node is a three-part layout:
+-----------------------+---------------------+
| Order of labelling | Final value |
+-----------------------+---------------------+
| Working values: 10(B), 8(A) |
+---------------------------------------------+Step-by-Step Procedure
- Set the source node to Order 1 with a permanent final value of 0.
- From the node just made permanent, calculate candidate distances to every unlabelled neighbouring node directly connected to it:
In a directed network, only follow edges pointing in the direction of the arrow. If the candidate value is strictly less than 's existing working value (or if has none yet), update 's working value to this candidate.
- Inspect all unlabelled vertices across the entire network. Select the vertex with the smallest working value and declare it permanent. Assign it the next sequential order number and record that working value as its final value. If there is a tie for the smallest value, either node may be chosen next.
- Repeat steps 2 and 3 until the destination vertex is made permanent.
- Trace backwards from the destination to find the path. An edge from to lies on a shortest path if:
If more than one predecessor satisfies this equation, multiple shortest paths of identical length exist.
Dynamic Programming and Bellman's Principle
Dynamic programming solves complex multi-stage decision problems by decomposing them into smaller subproblems. It relies on Bellman's Principle of Optimality:
An optimal policy has the property that whatever the initial state and initial decision are, the remaining decisions must constitute an optimal policy with regard to the state resulting from the first decision.
In plain English, every section of an optimal path must itself be optimal. If the cheapest route from Dublin to Galway passes through Athlone, the Athlone-to-Galway portion must be the cheapest possible way to travel between those two points. If a cheaper path from Athlone to Galway existed, substituting it would reduce the overall journey cost, contradicting the claim that the initial route was optimal.
Algebraic Formulation
Dynamic programming operates by backward induction — working from the terminal destination backwards to the source across a weighted directed acyclic network. Let denote the optimal (minimum) cost from state to the destination :
Where is the immediate cost of transitioning from state to state , and is the optimal cost from state onwards. For maximisation problems, replace with .
Setting Out the Table
Define your stage, state, and action in words before calculating. A standard layout uses five columns:
- Stage (): The decision step, conventionally indexed by the number of stages or time periods remaining until the horizon.
- State (): The physical condition, location, or available stock at the start of the stage.
- Action (): The decision taken.
- Destination (): The resulting state in the next stage.
- Value: The combined payoff: .
Mark the optimal choice for each state with an asterisk (). When the table is complete, trace the optimal policy forward from the initial state.
Dynamic Programming Archetypes
The Leaving Certificate specification identifies four distinct applications of dynamic programming:
1. Multi-Stage Routing
Finding the cheapest or quickest route through a directed acyclic network. Stages represent steps remaining, states represent junctions, and actions represent the chosen edge. The value is calculated as .
2. Stock Control (Inventory Management)
Determining monthly production to meet known customer demand while minimising the sum of production setups, unit costs, and storage fees.
- State (): Opening stock at the start of the month.
- Action (): Number of units manufactured.
- Destination (): Closing stock carried into the next month, governed by:
- Value: .
3. Allocation of Resources
Distributing a fixed, finite resource (such as capital or raw materials) across competing divisions to maximise total profit.
- Stage: Product line or project being funded.
- State (): Units of resource still available to allocate.
- Action (): Units allocated to the current product ().
- Destination (): Units remaining for subsequent stages ().
- Value: .
For example, if 4 tonnes of raw material remain for two divisions, allocating 1 tonne to division A gives a profit of €120. If the optimal profit from allocating the remaining 3 tonnes to division B is , the value is .
4. Equipment Replacement and Maintenance
Deciding when to replace an asset over an -year horizon to minimise overall net expenditure.
- Asset bought new each cycle: If a new asset is purchased and kept for years before trade-in, compute the cycle cost first:
The recurrence relation with years remaining is and .
- Asset already owned: If the firm currently owns an asset, let the state be the age of the asset at the start of the year, and stage be years remaining. The two actions are Keep (pay that year's maintenance; age increases by 1) or Replace (trade in at resale value, pay new purchase price, pay year-1 maintenance; age becomes 1 next stage).
Project Scheduling: Networks and Passes
A project consists of interdependent activities. We model this using an activity-on-arc network, where directed arrows represent activities (with durations) and event nodes represent milestone moments in time.
Examination Question Structure
A 50-mark project scheduling question typically follows a set sequence of tasks:
- Draw the network from the precedence table using dummy activities where necessary.
- Carry out the forward pass to determine early times.
- Carry out the backward pass to determine late times.
- Complete the float table for all activities.
- State the critical path(s) and minimum project completion time.
- Interpret the effect of delays or scheduling changes on the project completion date.
Drawing from Precedence Tables and Dummies
- Ensure the network has exactly one source node (start) and one sink node (finish).
- Number event nodes so that every directed arc goes from a lower-numbered node to a higher-numbered node.
- A dummy activity (duration 0, drawn as a dashed line) is needed in two situations:
- Logical dependency: Activity C depends on A and B, but activity D depends only on A. Drawing a dummy from the end of A to the start of C enforces this without delaying D.
- Uniqueness: Two activities share the same start and finish events. Because an activity must be uniquely identified by its pair of events , a dummy separates their terminal nodes.
Calculating Event Times
Every event circle is split into the early time (or earliest event time, EET) and the late time (or latest event time, LET).
- Forward Pass (Early Times): Set . Moving forward from source to sink:
Take the maximum where paths converge, because an event cannot occur until the slowest prerequisite activity finishes. The early time of the sink gives the minimum project completion time.
- Backward Pass (Late Times): Set . Moving backward from sink to source:
Take the minimum where paths diverge backwards, because each event must occur early enough to meet the tightest subsequent deadline. Always check that .
Total Float, Critical Paths, and Delays
For an activity running from event to event with duration :
- Earliest start:
- Earliest finish:
- Latest finish:
- Latest start:
Total Float
The total float is the maximum duration an activity can be delayed without delaying the entire project:
Critical Paths
An activity is a critical activity if and only if its total float is 0:
High-Level Distinction: Having at both end nodes is a necessary condition, but not a sufficient condition. For instance, if event 1 has early and late times of 0, event 4 has early and late times of 10, and an activity connecting them takes 7 days, its float is days. The activity is not critical despite running between two critical events.
The critical path is a continuous sequence of zero-float activities from the source node to the sink node. It is the longest-duration path through the network and dictates the minimum project completion time.
Evaluating the Effect of Delays
If an activity with total float is delayed by time units:
- If , the overall project duration is unchanged, although other activities sharing that float window may lose flexibility.
- If , the project completion time increases by time units, and the critical path may shift to run through that delayed activity.
Gantt Charts
A Gantt chart plots activities on a horizontal time axis. Each activity is drawn as a solid bar starting at its earliest start time for its duration, followed by a dashed line showing its total float up to its latest finish. A vertical line at time shows which activities must be happening (critical activities) and which could be happening (non-critical activities whose float window spans ).
Key terms
- Dijkstra's Algorithm
- A greedy algorithm that finds the shortest path from a single source vertex to all other vertices in a network with non-negative edge weights by iteratively giving permanent labels to nodes with the smallest working values.
- Bellman's Principle of Optimality
- The principle that an optimal policy has the property that, whatever the initial state and decision are, the remaining decisions must constitute an optimal policy with regard to the state resulting from the first decision.
- Stage
- A distinct step or time period in dynamic programming, numbered in reverse order by the number of decisions or time units remaining.
- State
- The physical condition, location, asset age, or inventory level of the system at the start of a dynamic programming stage.
- Action
- A feasible decision chosen from a state that transitions the system into a destination state at the subsequent stage.
- Optimal Policy
- The complete sequence of optimal decisions specifying the best action to take from every state across all stages to achieve the global optimum.
- Early Time
- The earliest possible time an event milestone can occur (also called earliest event time, EET), determined on the forward pass by taking the maximum of incoming (early time + duration).
- Late Time
- The latest possible time an event milestone can occur without extending the project duration (also called latest event time, LET), found on the backward pass by taking the minimum of outgoing (late time - duration).
- Total Float
- The amount of time an activity can be delayed without delaying the completion of the overall project, given by late time of finish event - early time of start event - duration.
- Critical Path
- A continuous sequence of zero-float activities from the source event to the sink event that determines the minimum project completion time; it is the longest-duration path through the project network.
- Dummy Activity
- A zero-duration, zero-cost directed dashed arc used in an activity-on-arc network to preserve unique node numbering or enforce logical dependencies without adding unnecessary constraints.
- Cycle
- A closed path in a network that starts and finishes at the same vertex without repeating any edge. A network without cycles is acyclic.
Check yourself
In Dijkstra's algorithm, what rule determines which unlabelled vertex is selected to receive a permanent label next?
You inspect all uncompleted nodes across the entire network and select the node with the smallest cumulative working value.
Why does Dijkstra's algorithm fail if a network contains negative edge weights?
Dijkstra's optimality proof assumes that adding non-negative edges can never shorten an existing path. If negative weights exist, a path passing through a node with a larger working value could later become shorter, invalidating permanent labels.
An activity with duration 6 days runs from Event 2 (early time = 4, late time = 5) to Event 5 (early time = 12, late time = 14). What is its total float, and is it critical?
Total Float = late time(5) - early time(2) - duration = 14 - 4 - 6 = 4 days. Because its float is 4 (not 0), the activity is not critical.
A machine costs €20,000 new, can be kept at most 2 years, maintenance is €1,000 in Year 1 and €3,000 in Year 2, and resale is €15,000 after 1 year and €9,000 after 2 years. Find cycle costs c(1) and c(2), and the cheapest replacement plan for a 3-year horizon.
c(1) = 20,000 + 1,000 - 15,000 = €6,000; c(2) = 20,000 + (1,000 + 3,000) - 9,000 = €15,000. Dynamic programming gives f(1) = 6,000; f(2) = min(6,000 + 6,000, 15,000) = €12,000; f(3) = min(6,000 + 12,000, 15,000 + 6,000) = €18,000 (buy new each year, total €18,000).
In a dynamic programming inventory problem, opening stock is 2, production is 5, and customer demand is 4. What is the destination state?
Closing stock = 2 + 5 - 4 = 3 units. The destination state for the next stage is 3.
