The Traveling Salesman Problem (TSP) is a classic algorithmic problem that asks: given a list of cities and the distances between each pair, what is the shortest possible route that visits each city exactly once and returns to the origin city? It is a fundamental benchmark in combinatorial optimization and computer science, belonging to the class of NP-hard problems, meaning no known algorithm can solve all instances efficiently as the number of cities grows.
Glossary
Traveling Salesman Problem (TSP)

What is Traveling Salesman Problem (TSP)?
A foundational challenge in computer science and operations research, the Traveling Salesman Problem (TSP) seeks the most efficient route through a network of points.
Despite its computational complexity, TSP is solved in practice using exact algorithms like branch-and-bound for smaller instances and powerful heuristic methods such as genetic algorithms, simulated annealing, and ant colony optimization for large-scale, real-world applications. Its relevance extends beyond routing salespeople to logistics, DNA sequencing, microchip manufacturing, and any domain requiring the optimization of a Hamiltonian cycle.
Key Characteristics of the TSP
The Traveling Salesman Problem (TSP) is defined by a specific set of mathematical properties that make it a foundational benchmark in combinatorial optimization and computational complexity.
NP-Hard Complexity
The TSP is a classic NP-hard problem, meaning no known algorithm can solve all instances in polynomial time. As the number of cities grows, the solution space expands factorially: for n cities, there are (n-1)!/2 possible tours. A 20-city problem has ~6×10¹⁶ possible routes, making brute-force enumeration computationally intractable. This intractability drives the need for heuristic and metaheuristic solution methods in practical applications.
Hamiltonian Cycle Requirement
A valid TSP solution must form a Hamiltonian cycle—a closed loop that visits every node exactly once and returns to the origin. This distinguishes the TSP from simpler pathfinding problems. The constraint eliminates subtours and ensures the route is a single, continuous circuit. In graph-theoretic terms, the solution is a Hamiltonian cycle of minimum total edge weight in a weighted complete graph.
Symmetric vs. Asymmetric Variants
The TSP has two primary variants based on distance reciprocity:
- Symmetric TSP (STSP): The cost from city A to B equals the cost from B to A. Common in Euclidean distance problems.
- Asymmetric TSP (ATSP): Costs differ by direction, modeling one-way streets, airfares, or time-dependent travel. ATSP is more general and computationally harder, requiring directed graph representations.
Metric vs. Non-Metric Instances
A metric TSP satisfies the triangle inequality: the direct path between two cities is never longer than a path through an intermediate city. This property enables approximation algorithms with provable guarantees, such as the Christofides algorithm which achieves a 3/2-approximation ratio. Non-metric instances lack this property and are significantly harder to approximate, often requiring general-purpose solvers.
Exact Solution Methods
Despite NP-hardness, exact solvers can handle surprisingly large instances using:
- Branch and Bound: Systematically partitions the solution space, pruning suboptimal branches using lower-bound heuristics like the Held-Karp 1-tree relaxation.
- Cutting Plane Methods: Iteratively adds linear constraints to eliminate fractional solutions in integer programming formulations.
- Branch and Cut: Combines both approaches and is the backbone of the Concorde TSP Solver, which has optimally solved instances with over 85,000 cities.
Heuristic and Metaheuristic Approaches
For large-scale or real-time applications, approximate methods dominate:
- Nearest Neighbor: A greedy constructive heuristic that builds a tour by always visiting the closest unvisited city. Fast but can produce poor solutions.
- 2-opt and 3-opt: Local search improvements that iteratively swap edges to eliminate crossings and reduce tour length.
- Lin-Kernighan Heuristic (LKH): A powerful variable-depth local search that remains the gold standard for near-optimal solutions on massive instances.
- Ant Colony Optimization and Genetic Algorithms: Bio-inspired metaheuristics that explore the solution space through population-based search.
Frequently Asked Questions
Clear, technical answers to the most common questions about the Traveling Salesman Problem, its computational complexity, and its critical role in modern logistics and AI-driven optimization.
The Traveling Salesman Problem (TSP) is a classic combinatorial optimization challenge that asks: 'Given a list of cities and the distances between each pair, what is the shortest possible route that visits each city exactly once and returns to the origin city?' It works by searching a discrete solution space of possible permutations. For n cities, the number of possible routes is (n-1)!/2, making brute-force enumeration computationally intractable for even modest problem sizes. The objective is to minimize the total tour cost, which can represent distance, time, or fuel consumption. TSP serves as a benchmark for algorithmic efficiency and is foundational to prescriptive analytics in logistics, where it models real-world routing constraints.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Mastering the Traveling Salesman Problem requires understanding the broader ecosystem of combinatorial optimization, heuristic search, and constraint-based reasoning that powers modern prescriptive analytics.
Vehicle Routing Problem (VRP)
A direct generalization of TSP where a fleet of vehicles with limited capacity must service a set of customers. VRP adds constraints like vehicle capacity, time windows, and depot returns, making it the practical logistics counterpart to TSP's theoretical purity. Real-world applications include last-mile delivery, waste collection, and school bus routing.
Constraint Programming
A declarative paradigm where you state the rules of the problem rather than the steps to solve it. Unlike TSP's explicit route construction, constraint programming lets a solver handle the search. Key techniques include:
- Arc consistency to prune impossible values
- Backtracking search with constraint propagation
- Global constraints like
all_differentfor visit uniqueness Ideal for highly constrained scheduling and routing variants.
Mixed-Integer Linear Programming (MILP)
The mathematical backbone for solving TSP exactly. MILP formulates TSP using binary decision variables (1 if edge is used, 0 otherwise) and linear constraints. The subtour elimination constraints prevent disconnected cycles. Commercial solvers like Gurobi and CPLEX use MILP with branch-and-cut to solve instances with thousands of nodes to proven optimality.
Simulated Annealing
A probabilistic metaheuristic inspired by metallurgical annealing. The algorithm accepts worse solutions with a probability that decreases over time, escaping local optima that trap greedy TSP solvers. Key parameters:
- Temperature schedule: controls cooling rate
- Neighborhood structure: often 2-opt or 3-opt edge swaps
- Acceptance probability:
exp(-ΔE / T)Excels on large TSP instances where exact methods fail.
Dynamic Programming
The Held-Karp algorithm solves TSP exactly in O(n²·2ⁿ) time using dynamic programming. It builds solutions by defining state dp[mask][i] as the shortest path visiting the set of cities in mask and ending at city i. While still exponential, this is dramatically faster than naive O(n!) enumeration and remains the fastest known exact algorithm for general TSP.
Branch and Bound
An exact algorithm that systematically partitions the solution space while using lower bounds to prune unpromising branches. For TSP, common bounding techniques include:
- Minimum spanning tree lower bound
- 1-tree relaxation
- Assignment problem relaxation When a branch's lower bound exceeds the best known solution, that entire subtree is discarded, dramatically reducing search space.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us