Traveling Salesman Solver — Find the Shortest Route Through Every City
Our Traveling Salesman Solver finds the exact minimum-cost tour that visits every city exactly once and returns to the starting city, given a distance matrix between cities, using the Held-Karp bitmask dynamic-programming algorithm — an exact method deliberately scoped to at most 12 cities since the problem is NP-hard in general.
Quick Answer
Enter a distance matrix between cities to instantly find the exact shortest round-trip tour via Held-Karp dynamic programming.
Enter one row per city, comma-separated distances, e.g. 0,10,15,20 then 10,0,35,25. Up to 12 cities.
How to Use the Traveling Salesman Solver — Exact Held-Karp DP Online
- 1
Enter a distance matrix, one row per city, with comma-separated distances, e.g. 0,10,15,20 then 10,0,35,25 and so on.
- 2
The matrix should be square, with each entry giving the distance between two cities (diagonal entries are typically 0).
- 3
Click 'Calculate' to find the exact optimal tour via Held-Karp dynamic programming.
Why Use Traveling Salesman Solver — Exact Held-Karp DP Online?
The traveling salesman problem asks for the shortest possible route that visits every city exactly once and returns to the start — a classic NP-hard problem where brute-force checking all (n−1)!/2 possible tours becomes impossible past a handful of cities. The Held-Karp algorithm improves dramatically on brute force using dynamic programming over subsets: it tracks, for every subset of visited cities and every possible ending city, the cheapest way to reach that state, building up from small subsets to the full set in O(n² · 2ⁿ) time instead of O(n!). That's still exponential, so this calculator caps the problem at 12 cities, where Held-Karp remains comfortably fast while still finding the exact, provably optimal tour (not just a good approximation).
Frequently Asked Questions
Related Tools
Hamiltonian Path Checker — Visit Every Node Once Online
Check whether a graph has a Hamiltonian path — a path visiting every node exactly once — via backtracking search. Free calculator, scoped to graphs of up to 10 nodes.
Minimum Spanning Tree Calculator — Kruskal's Algorithm Online
Find the minimum spanning tree of a weighted graph using Kruskal's algorithm. Free calculator with a simple edge-list input and union-find cycle detection.
Linear Programming Solver — 2-Variable Corner-Point Method Online
Solve a 2-variable linear program by finding and evaluating every corner point of the feasible region. Free calculator, maximize or minimize with linear constraints.