The travelling salesman problem, explained
Why finding the shortest round trip through a list of cities is so hard to solve exactly, and how good-enough answers are found anyway.
Written by Amili, an AI writer, from the sources listed below · 18 October 2026 · 6 min read
The travelling salesman problem asks for the shortest route that visits every city on a list exactly once and returns home. It is NP-hard, so no known method solves every case quickly, yet heuristics and clever exact methods handle very large instances in logistics, chip manufacturing and more.
In short
- The task is simple to state: given cities and the distances between them, find the shortest closed tour.
- The number of possible tours explodes as cities are added, so checking them all quickly becomes impossible.
- It is NP-hard; no algorithm is known that solves every instance in time that grows only polynomially.
- Exact methods such as cutting planes and branch-and-bound have still solved instances with tens of thousands of cities.
- Simple rules of thumb, like always going to the nearest city next, generally do not give the shortest tour.
What exactly is the travelling salesman problem?
Picture a list of cities and a table giving the distance between every pair. The travelling salesman problem, or TSP, asks for the shortest possible route that starts at one city, visits each of the others exactly once, and comes back to the start. Each city could stand for anything that must be visited, and the distance could be time, cost, or some other measure of separation.
It belongs to combinatorial optimization, the study of picking the best option from a finite but enormous set of possibilities. It was formulated in 1930 and has become one of the most heavily studied problems in the field, partly because it is so easy to describe and so stubborn to solve, and it now serves as a standard benchmark for testing optimization methods.
Why is it so hard to solve?
The obvious approach is to list every possible tour, measure each, and keep the shortest. That always works in principle, but the number of tours grows explosively with the number of cities. Each extra city multiplies the options rather than adding to them, so a method that is instant for a handful of cities becomes hopeless for a few dozen.
Computer scientists classify the TSP as NP-hard. The yes-or-no version, which asks whether some tour is shorter than a given length, is NP-complete. In practical terms, this means no one knows an algorithm that is guaranteed to find the best tour for every instance in time that grows only polynomially with the number of cities; the worst-case time may grow faster, though not beyond exponential. Richard M. Karp's 1972 result on Hamiltonian cycles supplied the formal explanation for why optimal tours had proved so hard to find.
What does a small example show?
Imagine five towns: four spaced roughly around a ring and one near the middle. Starting from any town, a tempting rule is to always drive to the nearest town not yet visited. That rule is quick, but it can leave the last legs of the trip stranded far apart, forcing a long jump back home at the end.
With only five towns in a symmetric map, where each road is the same length in both directions, there are just 12 genuinely different round trips, so all of them can be checked by hand. Add a few more towns and the count runs into the thousands, then millions. This is why the nearest-neighbour rule is popular despite its flaws, and why researchers as early as the 1930s, including Karl Menger, noted that it generally fails to give the shortest route.
How do people solve it in practice?
There are two broad strategies. Exact methods aim for a guaranteed best tour. In the 1950s, a RAND Corporation team of Dantzig, Fulkerson and Johnson framed the tour question as an integer linear program, then used a technique called cutting planes, adding constraints that rule out impossible solutions, to prove an optimal tour through 49 cities. Combined with branch-and-bound, which splits the problem into pieces and discards those that cannot beat the best tour found so far, these ideas later solved instances with 2,392 cities and, eventually, tens of thousands.
Approximation methods settle for a tour that is provably close to the best. One early approach builds a minimum spanning tree, the cheapest network connecting all cities, and uses it to guarantee a tour at most twice the optimal length. In 1976, Christofides and Serdyukov independently found a simple method that is never more than 1.5 times the optimum, and that bound stood as the best general guarantee until small improvements arrived in 2011 and 2020. Heuristics without such guarantees often do far better in practice; instances with millions of cities can get within a small fraction of a percent of the best tour.
Where does the TSP show up, and where does the model fall short?
Even in its plain form the TSP appears in planning, logistics and microchip manufacturing, where a machine must visit many soldering points. Warehouse order picking is often modelled as a variant, with a worker visiting storage locations and returning to a drop-off point. In modified forms it turns up in DNA sequencing, where the 'cities' are DNA fragments and 'distance' measures how similar they are, and in astronomy, where telescopes must move efficiently between targets.
The pure version leaves out much of real life. Deliveries often face time windows, limited vehicle capacity or several vehicles at once, which is why generalizations such as the vehicle routing problem exist. A perfect solution to the textbook problem can be the wrong answer to the business problem if those constraints are ignored.
What does the TSP teach about thinking?
The TSP shows that a problem can be easy to state and still be hard to solve, and that a greedy choice made at each step can lead to a poor overall result. Optimizing each move in isolation is not the same as optimizing the whole journey.
It also shows the value of settling for good enough. When the perfect answer is out of reach, a method with a known worst case, or a heuristic that is close to optimal almost every time, is often the more sensible goal than an exact answer that would take too long to find.
Questions people ask
Has the travelling salesman problem been solved?
In one sense, yes: specific instances, including some with tens of thousands of cities, have been solved exactly, and huge instances can be approximated very closely. In the general sense, no: no known algorithm finds the optimal tour for every instance in polynomial time, and whether such an algorithm can exist is tied to major open questions in complexity theory.
Why doesn't going to the nearest city each time give the best route?
The nearest-neighbour rule makes the best-looking choice at each step without considering what comes after. Early cheap moves can leave the remaining cities scattered, forcing long detours or a long final trip home. Mathematicians in the 1930s already observed that this rule generally does not produce the shortest tour, which is why better heuristics and exact methods were developed.
What is the TSP used for in real life?
It underlies route planning in logistics, warehouse order picking, and the drilling or soldering paths used in microchip manufacturing. Modified versions appear in DNA sequencing and in scheduling telescope observations. Real applications usually add constraints such as time windows or limited resources, which leads to related problems like vehicle routing.
The thinking behind it
Its chapter on relaxation uses problems like the travelling salesman to show when a good-enough answer beats a perfect one.
Read or listen to Algorithms to Live By
Hear the whole book free: start an Audible trial and your first audiobook — this one, if you like — is on the house.
As an Amazon Associate, ReadGlobe earns from qualifying purchases and Audible trials — at no extra cost to you.
Sources
- Travelling salesman problem — Wikipedia
- Combinatorial optimization — Wikipedia
How this was made: Amili, an AI writer, wrote this article in its own words from the sources above. Every link was checked before publishing. Spotted an error? Tell us and we will correct it.