Traveling salesman example with known global optimum
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction to the Traveling Salesman Problem
The Traveling Salesman Problem (TSP) is a classic optimization problem that has been extensively studied in the field of computer science and operations research. It poses a simple question: Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city?
The challenge lies in the exponential growth of possible routes, as the number of cities increases. The TSP is known to be NP-hard, which means there is no known algorithm that can solve all instances of the problem efficiently (in polynomial time). However, specific instances with known global optima can help us understand potential solutions and optimization techniques.
Technical Explanation
Problem Representation
The TSP can be represented mathematically as follows:
• Cities: • Distances: is the distance between city and city .
Objective: Find a permutation of cities that minimizes the total travel distance:
Known Global Optimum Example
One widely discussed example with a known global optimum is the Groetschel 49-city problem. It includes 49 cities with specified Euclidean distances and an established minimum tour length.
Key Features of the Groetschel Example
• Number of cities: 49 • Type: Symmetric TSP (distances are equal in both directions) • Optimal tour length: 21282.5 (unit distance)
The optimal solution for this instance helps benchmark TSP solving algorithms and validates their accuracy.
Solving Techniques
While finding the exact solution for larger instances remains computationally challenging, several strategies can be employed:
Exact Algorithms
- Branch and Bound: A tree-based search strategy that prunes paths based on estimated lower bounds.
- Dynamic Programming: Known as the Held-Karp algorithm, it solves the problem with a time complexity of .
Approximation Algorithms
- Christofides’ Algorithm: Guarantees a tour no longer than 1.5 times the optimal tour length for metric TSPs.
- Nearest Neighbor: Constructs a path by iteratively visiting the nearest unvisited city.
- Genetic Algorithms and Simulated Annealing: These heuristic-based methods explore solution spaces stochastically.
Visualization and Practical Example
Consider a simple 5-city TSP example with the following distances:
| From/To | City 1 | City 2 | City 3 | City 4 | City 5 |
| City 1 | 0 | 10 | 15 | 20 | 25 |
| City 2 | 10 | 0 | 35 | 25 | 15 |
| City 3 | 15 | 35 | 0 | 30 | 20 |
| City 4 | 20 | 25 | 30 | 0 | 10 |
| City 5 | 25 | 15 | 20 | 10 | 0 |
The optimal tour for this specific setup can be evaluated manually or with an exact algorithm. The minimal path can be achieved by visiting the cities in a specific sequence to minimize the return distance to the start.
Summary Table
Here's a summarized comparison of various TSP strategies:
| Method | Type | Time Complexity | Applicability |
| Branch & Bound | Exact | Varies | Suitable for small to medium-sized problems |
| Dynamic Programming | Exact | Used for precise solutions to smaller instances | |
| Christofides’ Algorithm | Approx. | Provides guarantees within an approximation factor; useful for metric TSPs | |
| Nearest Neighbor | Heuristic | Fast but not optimal; typically forms part of more complex heuristics | |
| Genetic Algorithms | Heuristic | Useful for larger instances where optimality can be relaxed for speed |
Conclusion
Understanding the Traveling Salesman Problem with examples of known global optima allows researchers to refine techniques and evaluate the performance of algorithms. As computing capabilities grow, new methods continue to improve the feasibility of solving larger instances accurately and efficiently. The TSP serves as a classic problem that embodies the challenges of combinatorial optimization in computing.
Related reading
- Travelling Salesman with multiple salesmen with a limit on number of cities per salesman?
- Travelling salesman with repeat nodes dynamic weights
- Traversal of an n-dimensional space
- Traversal of cyclic directed graph
- Travelling Salesman with multiple salesmen?
- Tricks for improving iPhone UITableView scrolling performance?
- Traverse Matrix in Diagonal strips
- Traversing Line Segments

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.