Proofs: Karp's minimum mean cycle algorithm
These are the human proofs of Karp's minimum mean cycle algorithm, at full length.
Karp's formula gives the minimum cycle mean, and the walk at the minimizing vertex holds an optimal cycle full
This proof shows: correctness, termination.
Let be a finite directed graph with vertices, arcs of real weight , parallel arcs and self-loops allowed. For and let be the least weight of a walk with exactly arcs that ends at (and starts anywhere), with and if there is no such walk.
Termination and the table. Lines L2 to L5 run rounds over a finite arc list, and line L11 moves from to , so it stops after at most steps. By induction on , lines L3 to L5 set , which is : a walk of arcs to is a walk of arcs to some followed by an arc . The pointer is the last arc of a walk that attains , so following the pointers from traces such a walk backwards.
Fact 1 (decomposition). A closed walk splits into simple cycles, so its mean is a weighted average of their means and is at least , the least mean of a simple cycle. A walk with or more arcs visits at least vertex positions, so some vertex repeats and it contains a closed sub-walk. Hence has a cycle if and only if for some , and line L10 is correct.
From here on, has a cycle, and is the least mean of a cycle.
Fact 2 (shift). Replace by for a constant . Every walk with arcs loses , so , and . Every cycle mean drops by . So the formula and both drop by , the choice of at line L9 and the pointers do not change, and it suffices to prove the claims for . Assume from now on that : every cycle has weight at least 0, and some cycle has weight 0.
Lemma 3. For every with , .
Proof. Let be a walk of arcs to of weight . By Fact 1 it contains a closed sub-walk; removing it leaves a walk to with fewer arcs and weight at most , since the removed part has weight at least 0. Repeat until no vertex repeats: the result is a walk with arcs to and weight at most . So for this , and that term of the max is at least 0.
Lemma 4. Some has for every with , so its max is at most 0.
Proof. Let . It is finite: walks of length 0 have weight 0, and, as no cycle is negative, removing closed sub-walks as in Lemma 3 shows that the minimum over all lengths is attained by some walk with fewer than arcs. So . Let be a cycle of weight 0 with vertices in order. For each , (indices mod ), and the sum of these inequalities around is an equality because ; so each one is an equality.
Choose with attained by a walk with arcs. Follow from for arcs, ending at some . The walk followed by these arcs has arcs and, by the equalities, weight . So for every .
Theorem 5 (Karp's formula). , so line L9 ends with .
Proof. With : every max is at least 0 by Lemma 3, and some max is at most 0 by Lemma 4, so the min is 0. The general case follows by Fact 2.
Theorem 6 (the cycle). The cycle returned by line L11 has mean .
Proof. With , the vertex chosen at line L9 has max equal to 0, so for every with . Line L11 traces a walk of arcs to of weight , and is a closed sub-walk of between two visits of the same vertex, with no vertex repeated inside it, so is a simple cycle with arcs. Removing from leaves a walk of arcs to of weight , so , which is finite, and . Also , so , the mean of is . By Fact 2 this holds for the original weights.