Algorithm Search⌘K

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 G=(V,A)G = (V, A) be a finite directed graph with n≥1n \ge 1 vertices, arcs of real weight ww, parallel arcs and self-loops allowed. For k≥0k \ge 0 and v∈Vv \in V let Dk(v)D_k(v) be the least weight of a walk with exactly kk arcs that ends at vv (and starts anywhere), with D0(v)=0D_0(v) = 0 and Dk(v)=∞D_k(v) = \infty if there is no such walk.

Termination and the table. Lines L2 to L5 run nn rounds over a finite arc list, and line L11 moves from (k,v)(k, v) to (k−1,u)(k - 1, u), so it stops after at most nn steps. By induction on kk, lines L3 to L5 set D[k][v]=min⁡(u,v)=aD[k−1][u]+w(a)D[k][v] = \min_{(u, v) = a} D[k-1][u] + w(a), which is Dk(v)D_k(v): a walk of kk arcs to vv is a walk of k−1k - 1 arcs to some uu followed by an arc (u,v)(u, v). The pointer P[k][v]P[k][v] is the last arc of a walk that attains Dk(v)D_k(v), so following the pointers from (n,t)(n, t) 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 λ∗\lambda^*, the least mean of a simple cycle. A walk with nn or more arcs visits at least n+1n + 1 vertex positions, so some vertex repeats and it contains a closed sub-walk. Hence GG has a cycle if and only if Dn(v)<∞D_n(v) < \infty for some vv, and line L10 is correct.

From here on, GG has a cycle, and λ∗\lambda^* is the least mean of a cycle.

Fact 2 (shift). Replace ww by w′=w−cw' = w - c for a constant cc. Every walk with kk arcs loses kckc, so Dk′(v)=Dk(v)−kcD'_k(v) = D_k(v) - kc, and (Dn′(v)−Dk′(v))/(n−k)=(Dn(v)−Dk(v))/(n−k)−c(D'_n(v) - D'_k(v))/(n - k) = (D_n(v) - D_k(v))/(n - k) - c. Every cycle mean drops by cc. So the formula and λ∗\lambda^* both drop by cc, the choice of tt at line L9 and the pointers do not change, and it suffices to prove the claims for w′=w−λ∗w' = w - \lambda^*. Assume from now on that λ∗=0\lambda^* = 0: every cycle has weight at least 0, and some cycle has weight 0.

Lemma 3. For every vv with Dn(v)<∞D_n(v) < \infty, max⁡0≤k<n, Dk(v)<∞(Dn(v)−Dk(v))/(n−k)≥0\max_{0 \le k < n,\ D_k(v) < \infty} (D_n(v) - D_k(v))/(n - k) \ge 0.

Proof. Let WW be a walk of nn arcs to vv of weight Dn(v)D_n(v). By Fact 1 it contains a closed sub-walk; removing it leaves a walk to vv with fewer arcs and weight at most Dn(v)D_n(v), since the removed part has weight at least 0. Repeat until no vertex repeats: the result is a walk with k<nk < n arcs to vv and weight at most Dn(v)D_n(v). So Dk(v)≤Dn(v)D_k(v) \le D_n(v) for this kk, and that term of the max is at least 0. □\square

Lemma 4. Some vv has Dn(v)≤Dk(v)D_n(v) \le D_k(v) for every k<nk < n with Dk(v)<∞D_k(v) < \infty, so its max is at most 0.

Proof. Let δ(v)=min⁡k≥0Dk(v)\delta(v) = \min_{k \ge 0} D_k(v). 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 nn arcs. So δ(v)=min⁡0≤k<nDk(v)\delta(v) = \min_{0 \le k < n} D_k(v). Let CC be a cycle of weight 0 with vertices c0,c1,…,cL−1c_0, c_1, \ldots, c_{L-1} in order. For each jj, δ(cj+1)≤δ(cj)+w(cj,cj+1)\delta(c_{j+1}) \le \delta(c_j) + w(c_j, c_{j+1}) (indices mod LL), and the sum of these inequalities around CC is an equality because w(C)=0w(C) = 0; so each one is an equality.

Choose c0c_0 with δ(c0)\delta(c_0) attained by a walk QQ with k0<nk_0 < n arcs. Follow CC from c0c_0 for n−k0n - k_0 arcs, ending at some cjc_j. The walk QQ followed by these arcs has nn arcs and, by the equalities, weight δ(cj)\delta(c_j). So Dn(cj)≤δ(cj)≤Dk(cj)D_n(c_j) \le \delta(c_j) \le D_k(c_j) for every kk. □\square

Theorem 5 (Karp's formula). λ∗=min⁡v:Dn(v)<∞max⁡0≤k<n, Dk(v)<∞(Dn(v)−Dk(v))/(n−k)\lambda^* = \min_{v : D_n(v) < \infty} \max_{0 \le k < n,\ D_k(v) < \infty} (D_n(v) - D_k(v))/(n - k), so line L9 ends with λ=λ∗\lambda = \lambda^*.

Proof. With λ∗=0\lambda^* = 0: 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. □\square

Theorem 6 (the cycle). The cycle CC returned by line L11 has mean λ∗\lambda^*.

Proof. With λ∗=0\lambda^* = 0, the vertex tt chosen at line L9 has max equal to 0, so Dn(t)≤Dk(t)D_n(t) \le D_k(t) for every k<nk < n with Dk(t)<∞D_k(t) < \infty. Line L11 traces a walk WW of nn arcs to tt of weight Dn(t)D_n(t), and CC is a closed sub-walk of WW between two visits of the same vertex, with no vertex repeated inside it, so CC is a simple cycle with L≥1L \ge 1 arcs. Removing CC from WW leaves a walk of n−Ln - L arcs to tt of weight Dn(t)−w(C)D_n(t) - w(C), so Dn−L(t)≤Dn(t)−w(C)D_{n-L}(t) \le D_n(t) - w(C), which is finite, and w(C)≤Dn(t)−Dn−L(t)≤0w(C) \le D_n(t) - D_{n-L}(t) \le 0. Also w(C)≥0w(C) \ge 0, so w(C)=0w(C) = 0, the mean of CC is λ∗\lambda^*. By Fact 2 this holds for the original weights. ■\blacksquare

Back to Karp's minimum mean cycle algorithm