Algorithms · Multistage Graph and 0-1 Knapsack
Multistage Graph: Definition and Shortest Path Problem
Overview
A multistage graph is a directed, weighted graph whose vertices are split into ordered stages, with edges only moving from one stage to the next.
The problem is to find the shortest path from the single source in stage 1 to the target (sink) in the final stage, and the stage structure is what makes a faster method than Dijkstra possible.
Key concepts
- Multistage graph: A directed, weighted graph whose vertices can be partitioned into groups called stages (sets) such that:
- there are no edges within a single stage (no edge between two vertices in the same set);
- all edges go only from stage to stage (from to ) — no edge from stage 2 back to stage 1, and no edge from stage 1 directly to stage 3.
- Source: Stage 1 contains exactly one node, called the source.
- Target / sink: The final stage (stage 4 in the example) contains a node called the target, sink, or destination.
- The problem: Find the shortest path from the source to the destination.
- Brute force: Enumerate all paths from source to target, compute the cost of each path, and take the minimum — very, very inefficient.
- Dijkstra from S: Valid here because the graph has no cycles, so there is no negative-weight edge problem and no negative-weight cycle problem (there is no cycle at all). Dijkstra can be applied without any issue.
- Dijkstra's drawback: Dijkstra is designed to find the shortest path from one node to all other nodes.
It finishes finding shortest paths to all nodes before it finds the shortest path to the destination, but only the source-to-destination path is wanted — the rest is unnecessary extra work. - Motivation for a better method: The graph is not a normal graph; its special stage structure can be exploited to get a lower running time than Dijkstra.

How it works
- Partition the vertices into stages .
- Verify the multistage conditions: no edges within any stage, and edges only from stage to stage .
- Identify the single source in stage 1 and the target/sink in the final stage.
- Find the shortest path from source to target, exploiting the stage-by-stage structure rather than solving the all-nodes problem.
Stage partition of the example graph (directed, weighted):
| Stage | Nodes |
|---|---|
| Stage 1 | S (source) |
| Stage 2 | A, B, C |
| Stage 3 | D, F |
| Stage 4 | T (target / sink) |
Characteristics verified on this graph:
- No edges between A, B, C (same stage), and similarly none within any other stage.
- Edges exist only from stage to stage (1 to 2, 2 to 3, 3 to 4).
- No edges from stage 1 to stage 3, and no backward edges from stage 2 to stage 1.
Formulas
- Dijkstra time complexity:
- = number of edges in the graph
- = number of vertices (nodes) in the graph
Comparison
| Approach | Idea | Efficiency |
|---|---|---|
| Brute force | Find all paths, compute cost of each, take minimum | Very, very inefficient |
| Dijkstra from S | Single-source shortest path from S to all nodes | ; computes shortest paths to all nodes, not just the destination — unnecessary extra time |
| Exploit multistage structure | Use the special stage-by-stage structure of the graph | Expected to be faster than Dijkstra (motivation for the next method) |
Revision summary
- A multistage graph is a directed weighted graph whose vertices are divided into stages.
- No edges within a stage; edges go only from stage to stage .
- Stage 1 has exactly one node (the source); the last stage has the target/sink.
- Brute force (all paths + minimum) is very, very inefficient.
- Dijkstra is applicable because the graph is acyclic — no negative-weight edge or negative-weight cycle problem — but it solves single-source-to-all, so it does extra work.
- Dijkstra's time is .
- The stage structure is a special characteristic worth exploiting to reduce time.
Previous-year exam insights
- In a multistage graph the shortest source-to-sink path is computed by dynamic programming: define cost(i, j) as the minimum cost from vertex j in stage i to the sink, with cost(N, sink) = 0 and cost(i, j) = min over edges (j, k) of { w(j, k) + cost(i+1, k) }, filling stages backward from N-1 to 1;
the answer is cost(1, source). - The forward (backward) DP over a k-stage graph with V vertices and E edges runs in time, i.e. linear in the size of the graph, which is strictly better than Dijkstra's .
- The number of distinct source-to-sink paths in a multistage graph can be exponential (product of branching across stages), so brute-force path enumeration is exponential-time; the DP avoids this by reusing subproblem solutions (optimal substructure).
- A multistage graph is a DAG, so its vertices admit a topological order (the stage order); shortest paths in any DAG can be found in by relaxing edges in topological order, which is the general principle behind the multistage DP.
- Dijkstra's algorithm requires non-negative edge weights; it is valid on a multistage graph because all weights are non-negative (and the graph is acyclic), but it is not the asymptotically fastest choice for this special structure.
- The DP recurrence can be computed either backward (cost from each vertex to the sink, stages N down to 1) or forward (distance from the source to each vertex, stages 1 up to N); both give the same optimal path cost, and the path itself is recovered by storing the decision (next/previous vertex) at each step.
Multistage graph stage structure
Drawing the diagram…
Shows the four stages of the example graph with edges only from stage i to stage i+1, from source S to sink T.