Past exam of the mathematics course of the University of Cambridge 2013 iii Paper 38 3 b Solution Created 2026-10-03 Updated 2026-10-07
For a minimum-cost flow with bounds , the capacitated flow optimality conditions consist of primal feasibility and network dual potentials whose network reduced costs obeyFor a zero-capacity edge both bounds coincide and no sign restriction is needed; all capacities here are positive. These are the bound form of complementary slackness. To derive necessity directly, construct the residual network: a possible increase has original cost and a possible decrease has reverse cost . An optimal flow cannot admit a negative-cost directed cycle, since a positive step around it preserves flow balance and lowers cost. If there is no such cycle, connect a new source by zero-cost edges to every vertex and let be shortest-path distances. They exist because no negative cycle is reachable. For every residual edge , . Taking makes every residual network reduced cost nonnegative, exactly the displayed sign conditions: both directions exist for an interior edge.
Conversely, for any other feasible flow , equal flow balances giveEach summand is nonnegative at a lower or upper bound, and zero at an interior edge. Hence the sign conditions suffice for optimality as well.
For the final flow, use in the order . All four tree edges have zero network reduced cost, while have costs . More explicitly, every feasible flow satisfiesOur flow attains equality. This gives a direct cost certificate of 220. The strict signs also force , at any optimum; flow balance then fixes all remaining edges, so this flow is unique.
Use the two-pass strongly connected component algorithm: first run depth-first search on the original directed graph, then search its graph transpose in decreasing order of the first pass's finishing times. The first-pass order from part (a) isReversing the edges gives outgoing adjacency listsThe second pass first visits only . Its next new root is , whose search visits ; later entries already marked by this search are skipped. The next new root is , whose graph transpose neighbours have already been assigned. Therefore the components areWithin the middle component the directed cycle demonstrates mutual reachability. The source edge structure does not provide return paths from or to . More generally, decreasing finish order chooses a remaining component whose graph transpose search cannot escape to another still-unassigned component, so each second-pass tree is exactly one component. This explains the partition rather than merely listing it. The algorithm takes with adjacency lists.[ref]
Depth-first search by Jeff Erickson. §§6.5–6.6, strong components, condensation and the two-search construction
Run depth-first search on Graph B with the same lexical convention and put each vertex on the front of the output when its search finishes. The finish order isso the returned topological order isFor example, both edges from point to later entries, the edges from point to and later in the order, and precedes . The construction is valid because in a Directed acyclic graph every edge has : a newly found descendant finishes before its caller, and an already finished neighbour also has a smaller finish time; an active ancestor would instead witness a directed cycle. Thus reversing the finish order puts every prerequisite before its successor. The time is .
The strongly connected components areThe directed cycle makes its three vertices mutually reachable. Vertex has no outgoing edge. Vertex reaches that cycle but has no return path from it, and vertex reaches the other components but has no incoming path from them. These facts exclude every further merger.
Robbins' theorem 2026-10-14
A finite nonempty connected graph whose edges are undirected admits a strong orientation if and only if it has no bridge in a graph. This statement holds for finite multigraphs as well as finite simple graphs; self-loops do not help connect distinct vertices. The single-vertex case is allowed, with length-zero directed paths.[ref]
On Orientations and Shortest Paths by Refael Hassin and others. Hassin and Megiddo, On Orientations and Shortest Paths (1989), printed pp. 591–592: bridge-connectedness, strong connectivity and Theorem 2.6 (Robbins)
Necessity comes from the two sides separated by deleting a bridge in a graph: its chosen arrow crosses in only one direction. For sufficiency, the cited constructive proof uses depth-first search to find a cycle in a graph, orients it cyclically, contracts it, and repeats. Undoing the contractions replaces junctions by directed cycles, retaining two-way reachability. Contraction can produce multiple edges, so these must remain distinct. This is a construction outline; the input graph is finite and bridgeless, and remaining edges within contracted pieces can receive arbitrary directions.[ref]
On Orientations and Shortest Paths by Refael Hassin and others. Hassin and Megiddo (1989), Theorem 2.6 proof, printed p. 592: cycle orientation and contraction, explicitly described as a different constructive proof from Robbins's
Shortest-path predecessor 2026-10-14
A shortest-path predecessor records the previous vertex on a chosen route from source to . When edge relaxation strictly improves through , set . For a multigraph, store the actual directed edge, since two edges with the same endpoints can have different weights. Initialize all vertices, including the source, without a shortest-path predecessor. The authored implementation reconstructs a route by following these incoming edges backwards, then reversing their order.[ref]
https://raw.githubusercontent.com/kevin-wayne/algs4/master/src/main/java/edu/princeton/cs/algs4/DijkstraSP.java. Sedgewick and Wayne, DijkstraSP.java, edgeTo and pathTo
At the end of the edge relaxation trace, , , and . Following them gives , so the forward directed path is , of cost . This makes the distance useful: a number tells us the best cost, whereas the shortest-path predecessors tell us which connections to take. In the Dijkstra algorithm, reconstruct a destination's shortest route after its label becomes permanent. In a label-correcting shortest-path algorithm, wait for convergence and the appropriate negative-cost directed cycle check. During correction, a predecessor's label may have changed since its child's last update: immediately after in the trace, the current chain to costs although still records the earlier discovered route of cost .
Strict improvement is a useful guard against directed cycles in the recorded pointers. Consider and of cost zero, followed by and , also of cost zero. After the first two edge relaxations, both labels are zero and both shortest-path predecessors are . If equality also allows pointer replacement, the last two operations can set and : following pointers loops forever despite correct distance labels. Keeping the old pointer on ties prevents this example; choosing among equal-cost routes requires a separate rule that preserves a route to the source. Strict improvement alone does not protect against reachable negative-cost directed cycles, which can force endless decreases. Equality on recorded edges plus the Bellman inequalities certifies route costs only when the pointer chains actually terminate at the source.
For all-to-one distances to , record a next vertex whenever relaxing improves . Follow these successors forward in the original directed graph to reach . They are shortest-path predecessors when viewed in the reversed directed graph; keeping the direction convention explicit prevents returning a route whose arrows point the wrong way.
Spanning circuit family 2026-10-14
A spanning circuit family is a collection of directed cycles whose union contains every vertex of the directed graph. Different circuits may overlap. This is distinct from a cycle cover of a directed graph, which requires vertex-disjoint cycles.
Spreadsheet circular reference 2026-10-14
A spreadsheet cell depends on itself along a nonempty directed path. For a separate formula-edit experiment, restore the initial inputs and replace only
B1 by =A1+A2+C1. Now B1 C1 B1 is a directed cycle. Requesting D1 makes D1,C1,B1 active and then requests the still-active C1; the algorithm reports C1,B1,C1 rather than returning an old value. This witness follows references backwards, opposite to our dependency arrows; reversing it gives a directed cycle in the spreadsheet dependency graph.D1 is not itself on that directed cycle, but it cannot receive a value from this evaluator because it needs C1. Independent requests for B2 and E1 still succeed. A topological order of the entire modified spreadsheet dependency graph is impossible: the two cyclic directed edges would require B1 before C1 and C1 before B1. For the initial inputs, the associated system of linear equations is even inconsistent: and imply . Detecting a directed cycle is a structural check, not an attempt to solve these linear equations. Spreadsheet dependency graph 2026-10-13
The directed graph whose vertices are the spreadsheet cells and whose directed edges mean that the spreadsheet formula in references . Input spreadsheet cells have no prerequisites in this model. Retain both incoming references and outgoing consumers: depth-first search for evaluation follows incoming references backwards, whereas downstream invalidation follows outgoing consumers forwards. A directed path then expresses indirect dependence, and a directed cycle expresses a spreadsheet circular reference.
State-transition diagram 2026-10-24
A directed graph with one vertex for each state and labelled edges for the permitted transitions. A finite counter has a directed cycle when every state has one successor.
Strong orientation 2026-10-14
A strong orientation is an orientation of a graph with strong connectivity: for every ordered pair of vertices, there is a directed path from to . A length-zero directed path permits . Ordinary connectivity of the underlying undirected graph is necessary, but does not ensure this two-way reachability after directions are chosen. The acyclic is not a strong orientation; the cyclic is, since a journey can continue around its directed cycle.
Attach a new vertex to that triangle in a graph by the single edge . This edge is a bridge in a graph. If oriented , no directed path leaves for the triangle in a graph; if oriented , no directed path from the triangle in a graph reaches . Neither choice gives a strong orientation, even when the triangle in a graph itself is cyclically oriented. By contrast, the four-vertex cycle graph has the strong orientationFollowing this directed cycle reaches any requested vertex in at most three steps. Removing any one of its undirected edges leaves a graph path through all four vertices, so it has no bridge in a graph.
For more than one vertex, a strong orientation cannot also be an acyclic orientation: directed paths from to and back give a nonempty closed directed walk, from which removing repeated portions leaves a directed cycle. A directed graph containing one directed cycle need not have strong connectivity, as the attached shows.
Synchronous Bellman-Ford recurrence 2026-10-18
For the single-source problem, let be the minimum cost of a directed walk from to using at most edges. Set and for , use for finite , and let a minimum over an empty set be . ThenEvery entry on the right comes from the previous round, requiring separate old and new arrays. The proof is the last-edge decomposition: a permitted directed walk either already uses at most edges, or ends with some after a prefix using at most . Conversely, each candidate describes a permitted directed walk. This dynamic programming viewpoint gives an exact meaning to every intermediate label, even when negative-cost directed cycles exist. Apply the formula to the source too: its initial zero is not a permanent constraint.
If no negative-cost directed cycle is reachable from , removing repeated-vertex portions of a directed walk cannot increase its cost. Whenever a destination is reachable, some shortest directed path therefore uses at most edges, and . Unreachable vertices keep distance . For in-place passes, every finite label still comes from a discovered directed walk; moreover, pass has offered every prefix of length of a shortest directed path, regardless of scan order. Its labels can improve faster than the synchronous labels, while the same upper bound on passes remains valid. This is why repeated local corrections eventually settle a global shortest path problem.
Tentative distance 2026-10-14
A tentative distance is the cheapest cost so far recorded by a shortest path problem algorithm. For the single-source convention, initialize and elsewhere. Every finite label is the cost of a discovered route from to , soIt is an upper bound supplied by an actual route, not a guess that might be too low. The loop invariant follows directly from edge relaxation: extending a discovered route to by supplies another discovered route. The usual label initialization and this safety property are stated and proved in the authored MIT notes.[ref]
https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-fall-2011/6277a1f06100c26a7ff21031af6757b5_MIT6_006F11_lec16.pdf. MIT 6.006, Lecture 16, p. 1: relaxation safety
In the trace under edge relaxation, first records the direct directed path . Later records , and finally records . Each label is a usable route cost, but the first two are not shortest. An infinite tentative distance means no route has yet been discovered; only a completed search establishes unreachability. The isolated vertex in that example remains at .
In a directed graph, the discovered route is formally a directed walk, which may repeat vertices; in the pictured acyclic graph it is always a directed path. Negative-cost directed cycles can keep supplying cheaper directed walks without a finite optimum. In the all-to-one convention, the same meaning applies to discovered routes from to . Do not confuse either version with the lower bounds supplied by feasible potentials in the Bellman inequalities: one records something achievable, the other rules out anything cheaper.
Topological order 2026-10-14
A topological order of a finite directed graph is a sequence containing every vertex exactly once, withThus every directed edge points forward in the list. Equivalently, a bijection assigning positions satisfies for every directed edge . A topological ordering names the same kind of list. [ref]
The toy Directed acyclic graph has exactly five topological orders: , , , , and . These lists were checked by enumerating all permutations and retaining precisely those satisfying all five directed edge inequalities. Every list ends with , since all other tasks have a directed path to publication. A topological order need not put adjacent entries next to one another in the directed graph: and are consecutive in without a directed edge between them.
A directed cycle would force the impossible chain of position inequalities . In the toy example, adding requires review before publication and publication before review, so there are no topological orders. Together with the construction in topological sorting, this proves that a finite directed graph admits a topological order if and only if it is a Directed acyclic graph. The empty directed graph has the empty sequence as its topological order.
There is also a useful connection to partial orders: define when or there is a directed path from to . For a Directed acyclic graph, this reachability relation is a partial order, and its linear extensions are exactly the topological orders. The Directed acyclic graph specifies which pairs must be ordered; a topological order chooses positions for all the remaining pairs.
Topological sorting Created 2026-10-14 Updated 2026-10-20
A topological sorting is the task of constructing a topological order of a finite directed graph, or reporting that a directed cycle makes one impossible. Kahn's algorithm repeatedly takes a vertex with no unfinished prerequisites. This is useful whenever an operation consumes results produced by earlier operations: once a vertex is reached in a topological order, every prerequisite along a directed path has already been processed. [ref]
The reason a choice is always available in a nonempty finite Directed acyclic graph is simple. If every vertex had an incoming directed edge, repeatedly following predecessors would eventually revisit a vertex, giving a directed cycle. Removing a vertex and its incident directed edges cannot create a directed cycle, so the argument repeats until every vertex is listed. This proves existence of a topological order and explains why finiteness matters to this procedure.
// Target: combinatorics.bigb
