Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The traveling salesman problem (TSP) asks for the least-cost tour that visits every required location exactly once and returns to where it started. In graph theory, it is the problem of finding a minimum-weight Hamiltonian cycle in a weighted graph.

What the traveling salesman problem means

Represent each location as a vertex and each possible trip between locations as an edge. Give each edge a weight for its cost, such as distance, travel time, or expense. The TSP is to choose a closed tour that visits every vertex once and has the lowest possible total edge weight.

The NIST Dictionary of Algorithms and Data Structures defines it as finding a path through a weighted graph that starts and ends at the same vertex, includes every other vertex exactly once, and minimizes the total cost of the edges. NIST’s entry, “traveling salesman,” was modified July 26, 2021.

In the familiar city example, the cities are vertices and the travel costs between them are edge weights. The objective is not necessarily geographic distance: “shortest” means least cost according to the chosen weights. OpenStax describes the basic version as finding a least-weight Hamilton cycle in a complete weighted graph (Contemporary Mathematics, section 12.9).

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How a TSP tour differs from a Hamiltonian path

  • Hamiltonian path: visits every vertex exactly once, but does not have to return to its starting vertex.
  • Hamiltonian cycle: visits every vertex exactly once and returns to its starting vertex.
  • Traveling salesman problem: seeks the minimum-cost Hamiltonian cycle. A cycle that obeys the visit rule is valid, but it is not necessarily optimal.

Optimization and decision versions

The optimization version asks which valid tour has the lowest total cost. The decision version asks whether there is a valid tour whose cost is at most a specified bound. These are related formulations, but they ask different questions: one seeks the best tour, while the other tests whether a tour meeting a threshold exists.

How solutions are found

Exhaustive search for small instances

A direct method lists the possible tours, calculates each tour’s total weight, and selects the least expensive. This can establish an optimum, but the number of candidate tours grows rapidly as locations are added, making exhaustive enumeration impractical for many larger instances. OpenStax presents this brute-force approach for introductory examples.

Rank #2
Sale
The Traveling Salesman Problem: A Computational Study (Princeton Series in Applied Mathematics)
  • New
  • Mint Condition
  • Dispatch same day for order received before 12 noon
  • Guaranteed packaging
  • No quibbles returns

Nearest-neighbor heuristic

A simple heuristic starts at one location, repeatedly travels to the cheapest unvisited location, and returns to the start after visiting them all. It is easy to apply and can produce a relatively low-cost route, but each choice is greedy: it considers the next move rather than guaranteeing the least-cost complete tour. The result may therefore be valid without being optimal.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When the basic definition needs qualification

The standard definition assumes a specified set of locations, a cost for each usable connection, and a tour that visits each location once before returning to its start. Real-world or mathematical variants can change those assumptions. For example, costs may be asymmetric, so traveling from A to B costs something different from traveling from B to A. Other versions add constraints such as delivery time windows, vehicle capacity, or precedence rules. Identify those conditions explicitly: they are not part of the basic TSP definition. IEEE’s Technology Navigator overview of traveling salesman problems discusses the family of variants.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.