Algorithm Search⌘K

Proofs: Little's algorithm

These are the human proofs of Little's algorithm, at full length.

Little's algorithm returns a shortest tour full

This proof shows: correctness, termination.

We use the pseudocode of the page. A tour is a set TT of n≥2n \ge 2 arcs that forms one cycle through all nn cities, and cost(T)=∑(u,v)∈Tcuv\mathrm{cost}(T) = \sum_{(u, v) \in T} c_{uv}, which is ∞\infty if TT has a forbidden arc. Let z∗z^* be the least cost of a tour, or ∞\infty if every tour has a forbidden arc. For a node (lb,M,S)(lb, M, S), let RR and KK be the rows and columns of MM: the cities with no arc of SS out of them, and the cities with no arc of SS into them. The node stands for the set T(lb,M,S)\mathcal{T}(lb, M, S) of tours TT with S⊆TS \subseteq T and Muv<∞M_{uv} < \infty for every (u,v)∈T∖S(u, v) \in T \setminus S.

Claim 1 (cost identity). For every node that the algorithm makes and every T∈T(lb,M,S)T \in \mathcal{T}(lb, M, S), cost(T)=lb+∑(u,v)∈T∖SMuv\mathrm{cost}(T) = lb + \sum_{(u, v) \in T \setminus S} M_{uv}, and Muv≥0M_{uv} \ge 0 for all entries.

Proof. Before line L1 reduces it, M=CM = C with ∞\infty on the diagonal, and lb=0lb = 0, S=∅S = \emptyset; the identity holds, as no tour uses a diagonal arc. We show that each operation keeps the identity and M≥0M \ge 0, for every tour that the node still stands for after the operation.

  • Row reduction by hh, the smallest entry of row u∈Ru \in R. A tour TT in the set uses exactly one arc out of uu, and since u∈Ru \in R it is not in SS, so its end is a column in KK. The sum in the identity loses hh and lblb gains hh. The new row has smallest entry 0. If h=∞h = \infty, the set is empty, and REDUCE returns ∞\infty.
  • Column reduction. The same, with arcs into a city of KK.
  • Setting an entry to ∞\infty (lines L10 and L12). The set of tours shrinks; the identity holds for the tours that remain, as the other entries do not change.
  • Fixing (i,j)(i, j) with Mij=0M_{ij} = 0 (line L11). For a tour T⊇S∪{(i,j)}T \supseteq S \cup \{(i, j)\}, the term Mij=0M_{ij} = 0 moves from the sum to S′′S'', and the other terms of T∖S′′T \setminus S'' lie in rows R∖{i}R \setminus \{i\} and columns K∖{j}K \setminus \{j\}, which M′′M'' keeps.

Each node is made from its parent by these operations, so the claim holds by induction. □\square

Claim 2 (bound and leaves). For every node, every T∈T(lb,M,S)T \in \mathcal{T}(lb, M, S) has cost(T)≥lb\mathrm{cost}(T) \ge lb. If ∣S∣=n|S| = n at line L6, then SS is a tour and cost(S)=lb\mathrm{cost}(S) = lb.

Proof. The first part follows from Claim 1, as M≥0M \ge 0. For the second, arcs are added only at line L11, with i∈Ri \in R and j∈Kj \in K, so SS has at most one arc out of each city and at most one into each city. If SS has no cycle, it is a set of disjoint paths, where a city with no arc of SS counts as a path with no arcs. The end ee of a path has no arc out, so e∈Re \in R, and its start ss has no arc in, so s∈Ks \in K.

We show the invariant: for every path s→⋯→es \to \cdots \to e of SS with fewer than n−1n - 1 arcs, Mes=∞M_{es} = \infty. For a path with no arcs this is the diagonal entry, which line L1 sets to ∞\infty. Reductions do not change entries equal to ∞\infty, and line L10 only adds one, so the invariant passes to the exclude child. In the include child, ii is the end of its path and jj the start of its path, and these two paths join into the path through (i,j)(i, j), for which line L12 sets Mes′′=∞M''_{es} = \infty when it has fewer than n−1n - 1 arcs. Every other path keeps its ends, which are not ii and not jj, so its entry is in a row and a column that M′′M'' keeps.

Now suppose that adding (i,j)(i, j) at line L11 closes a cycle. Then jj is the start and ii the end of the same path PP, and the cycle has ∣P∣+1|P| + 1 arcs. If ∣P∣+1<n|P| + 1 < n, the invariant gives Mij=∞M_{ij} = \infty, so (i,j)(i, j) is not a zero, a contradiction. So the only cycle SS can contain has nn arcs and is a tour. When ∣S∣=n|S| = n, the nn arcs with one out of each city and one into each city cannot all lie on paths, so SS is this tour; it lies in T(lb,M,S)\mathcal{T}(lb, M, S) with an empty sum, and Claim 1 gives cost(S)=lb\mathrm{cost}(S) = lb. □\square

Claim 3 (children split the parent). Let a node N=(lb,M,S)N = (lb, M, S) with ∣S∣<n|S| < n be split at lines L8 to L14 on (i,j)(i, j). Every T∈T(N)T \in \mathcal{T}(N) lies in the set of the exclude child N′N' or of the include child N′′N'', with the bounds lb+θ(i,j)lb + \theta(i, j) and lb+hlb + h that lines L10 and L13 compute, whether or not the child is inserted.

Proof. If (i,j)∉T(i, j) \notin T, then TT uses no arc with Muv′=∞M'_{uv} = \infty, so T∈T(N′)T \in \mathcal{T}(N'); the reduction of row ii subtracts min⁡k≠jMik\min_{k \ne j} M_{ik}, since Mij′=∞M'_{ij} = \infty and the other entries of row ii are those of MM, and then column jj has smallest entry min⁡k≠iMkj\min_{k \ne i} M_{kj}, so the bound is lb+θ(i,j)lb + \theta(i, j). If (i,j)∈T(i, j) \in T, then T⊇S′′T \supseteq S''. If ∣S′′∣<n−1|S''| < n - 1, the arc (e,s)(e, s) of line L12 together with the path s→⋯→es \to \cdots \to e of S′′S'' makes a cycle of fewer than nn arcs, which TT cannot contain, so TT does not use (e,s)(e, s) and T∈T(N′′)T \in \mathcal{T}(N''). □\square

Claim 4 (invariant). At the start of each iteration of line L3, every tour TT with cost(T)<z\mathrm{cost}(T) < z lies in the set of some live node.

Proof. At the start, the root stands for all tours of finite cost, and it is inserted unless its bound is ∞\infty, in which case no tour has finite cost. Suppose that the claim holds at the start of an iteration that takes NN and does not break, and let cost(T)<z\mathrm{cost}(T) < z at the end of the iteration. As zz only decreases, cost(T)<z\mathrm{cost}(T) < z held at the start, and TT was in the set of a live node. If that node is not NN, it is still live. If it is NN and ∣S∣=n|S| = n, then T=ST = S and line L7 sets z=cost(S)z = \mathrm{cost}(S), which contradicts cost(T)<z\mathrm{cost}(T) < z. Otherwise, by Claim 3, TT is in the set of a child with bound b≤cost(T)<zb \le \mathrm{cost}(T) < z by Claim 2; then the test at line L9 or line L14 passes and the child is inserted. □\square

Claim 5 (termination). The loop runs finitely often. Proof. Each child either has one more arc in SS (include) or one more entry equal to ∞\infty among the entries of its rows and columns (exclude, since Mij=0M_{ij} = 0 becomes ∞\infty). Along any path of the tree, the number of fixed arcs is at most nn, and between two include steps the number of finite entries, at most n2n^2, falls by at least one at each exclude step. So every path has length at most n+n3n + n^3, the tree is binary, and it is finite. □\square

Theorem. LITTLE(C)(C) returns (z∗,T)(z^*, T) for a tour TT of cost z∗z^* if z∗<∞z^* < \infty, and (∞,NIL)(\infty, \text{NIL}) otherwise.

Proof. By Claim 5 the loop ends. By Claim 2, zz is ∞\infty or the cost of the tour bestbest, so z≥z∗z \ge z^*. When the loop ends, either HH is empty, or the node taken has lb≥zlb \ge z and, as HH is a min-priority queue, every live node has bound at least zz. In both cases, Claim 4 and Claim 2 show that no tour has cost below zz: such a tour would lie in a live node with bound at most its cost, below zz. So z≤z∗z \le z^*, hence z=z∗z = z^*. If z∗<∞z^* < \infty, then bestbest is a tour of cost z∗z^*; if z∗=∞z^* = \infty, line L7 never runs, since a leaf has finite bound only if its tour has finite cost, and inserted nodes have bound below z=∞z = \infty; so best=NILbest = \text{NIL}. ■\blacksquare

Back to Little's algorithm