Kolton Ndoj

The traveling salesman: easy to check, brutally hard to solve

When delivery companies plan which parcel van stops where, or a drill plans its path across a circuit board

What problem does it solve?

What's the shortest round trip that visits every city exactly once?

The big idea

Finding the shortest path between two places is easy (Dijkstra). But a round trip through every city is a different beast: the number of possible tours explodes like a factorial, and no one has ever found a method guaranteed to be fast for every map. Yet if someone hands you a tour and claims 'this is under 1000 km', you can check it instantly. That gap, between checking an answer and finding one, is the heart of P vs NP, the biggest open question in computer science.

How it works, step by step

  1. 1. Brute force: list every possible tour and measure each (only feasible for about a dozen cities).
  2. 2. Greedy start: from each city, go to the nearest unvisited city, which is fast but often 20–25% too long.
  3. 3. Improve: find two crossing edges and uncross them (2-opt), and repeat until no swap helps.
  4. 4. For proof of the best answer, use clever branch-and-bound methods that rule out huge families of tours at once.

The key formula

tours=(n−1)!2\text{tours} = \frac{(n-1)!}{2}
nn
the number of cities
(n−1)!(n-1)!
fix the starting city, then arrange the other n − 1 in any order
12\tfrac12
a tour and its reverse are the same loop

How fast is it?

20 cities already gives about 6 × 10¹⁶ tours. The cleverest known exact method (Held–Karp, 1962) takes about n²·2ⁿ steps, which is still exponential. Real logistics uses fast heuristics that get within a few percent of the best tour. If anyone proves P = NP or P ≠ NP, the Clay Mathematics Institute will pay them $1,000,000.

Graph for The traveling salesman: easy to check, brutally hard to solve 360850
Number of digits in the number of possible tours for t cities (using Stirling's approximation of (t−1)!/2). At about 60 cities it reaches the roughly 10⁸⁰ atoms in the observable universe. (drawn with the default slider values — move the sliders live)

Try it yourself

Fun fact

In 2006 the Concorde program proved the optimal tour through 85,900 points, from a real computer-chip wiring problem. And for maps where distances obey the triangle inequality, Christofides' 1976 algorithm guarantees a tour at most 1.5 times the best, in fast polynomial time.

Related

Open it in the Math Lab →

Theory · Stretch