Proofs: Held-Karp algorithm
These are the human proofs of Held-Karp algorithm, at full length.
Held-Karp returns a shortest tour full
This proof shows: correctness, termination.
We use the pseudocode of the page, with cities , and distances , which are real numbers. For a nonempty and , an -path is a sequence with and . So it starts at 0, visits each city of exactly once, visits no other city, and ends at . Its length is . Let be the least length of an -path. It exists, because has finitely many orders and each order gives exactly one -path.
Lemma 1. After lines L2 to L6, for each nonempty and : (a) ; (b) if then , and if then lies in and .
Proof. First, each entry is written once and only after the entries it reads. Line L2 writes the sets of size 1. Line L5 for reads . If , the set has size 1 and was written by line L2. If , the mask of is the mask of minus the positive number , so it is smaller, and line L3 handled it in an earlier pass. So line L5 reads only final values.
We prove (a) by induction on .
Base, . Then , and the only -path is , with length . Line L2 sets and .
Step, . Assume (a) for all sets of size . Let , which is nonempty.
- Each value of line L5 is the length of a path. Take . By the hypothesis, some -path has length . Append to . Since , the result visits exactly the cities of , once each, and ends at . So it is an -path of length . Hence the minimum of line L5 is at least .
- An optimal path gives one of the values. Let be an -path of length , with . Let . Then because , and . The prefix is an -path, so its length is at least by the hypothesis. So , which is at least the minimum of line L5.
The two bounds give . Line L6 picks an that attains the minimum, which is (b).
Lemma 2. The least length of a tour is for .
Proof. A tour is exactly a -path followed by the edge back to 0, and its length is the length of the path plus . Conversely, each -path followed by the edge is a tour. So the set of tour lengths is the set of values (length of a -path) over all and all such paths, and its minimum is the stated one.
Lemma 3 (the rebuild). Lines L8 to L11 stop, and they produce a tour of length .
Proof. Each pass of line L11 with removes from , so drops by exactly 1. While , Lemma 1(b) gives a new , which is not 0. When , line L11 sets and the loop stops. So the loop runs exactly times.
We claim that before each test of line L9 with : , the list followed by nothing is a sequence of the cities of , and , where the length of the walk is the sum of over its consecutive pairs. At the start, , , is empty, and the claim holds. In a pass with , let . By Lemma 1(b), . After the pass, , the new list is , and the new walk is , whose length is plus the old one. So the sum is unchanged. In the last pass, , so and . After it, the list is a sequence of all of , and followed by the list is a walk of length that visits each city of once. Line L12 returns it, and the edge from back to 0 closes it into a tour of length .
Theorem. HELD-KARP stops and returns the least length of a tour and a tour of that length.
Proof. For , line L1 returns the only tour, of length 0. For , all loops of lines L2 to L6 run over finite sets, and the loop of line L9 stops by Lemma 3. By Lemma 1(a), line L7 computes , which is the least tour length by Lemma 2. By Lemma 3 the returned tour has length .