• Awards Season
  • Big Stories
  • Pop Culture
  • Video Games
  • Celebrities

Kate Bove

How Has a Year Without Tourists Impacted the Overtourism Problem?

methods travelling salesman problem

All press is good press — until that press goes too well. Although the Netherlands’ beautiful, canal-filled city of Amsterdam garners about $91.5 billion a year through tourism, the city and its residents feel more overwhelmed than grateful. In 2018, a whopping 18 million people visited Amsterdam, and experts estimate that number will climb to 42 million visitors by 2030. Longtime resident Ellen van Loon told CNN , “We [the Dutch] don’t want to turn into a Venice.”

Italy’s similarly canaled destination attracts 28 million visitors annually — while 2,000 residents abandon the city each year due to those same tourists. Of course, Amsterdam and Venice aren’t the only cities that have become synonymous with overtourism. In fact, hotspots all over the world, from beaches in Thailand to ancient sites in Peru, have simply attracted too many curious tourists. This phenomenon, known as overtourism, has led to environmental and ecological damage as well as a great deal of strain for locals who must navigate living amongst tourists and their economic impact.

Of course, the COVID-19 pandemic has stymied travel, shutting down airports, cities, borders and entire nations. According to the U.S. Travel Association , travel spending declined by an unheard of 42% in 2020; international and business travel suffered the most, with spending falling 76% and 70%, respectively. So, after a year of virtually no tourism, how are these (normally too heavily traveled) places, and the people that call them home, faring?

How Overtourism Impacts Some of the World’s Most Beautiful Destinations

Be it an ancient site, a crowded city or a place of natural splendor, popular destinations all feel the effects of overtourism differently. For example, Rapa Nui — often known to westerners as Easter Island — faces preservation issues, especially when it comes to the island’s famed moai sculptures. Meanwhile, the Galápagos Islands, the fragile and isolated ecosystem Charles Darwin popularized, has put a cap on how many visitors can travel to the archipelago each year. And in hotspot cities like Barcelona, Spain, locals are so furious with the unprecedented jump in tourists that they’ve coined a term to describe what overtourism is doing to the city: parquetematización — or the act of becoming a theme park.

methods travelling salesman problem

Some of the other most heavily impacted destinations include:

  • Santorini, Greece: Greece as a whole may be on the brink of an overtourism crisis. In 2018, the country hosted an unprecedented 32 million visitors, whereas back in 2010, that figure was closer to 15 million. The Greek National Tourism Organisation says it plans to strategically extend what is considered the summer holiday period so the influx of tourists doesn’t “[move] beyond the carrying capacity of the environment.” Of all locales, the small island of Santorini has been hit hardest, garnering a whopping 5.5 million annual visitors.
  • Machu Picchu: Peru’s most well-known Inca citadel is one of those destinations everyone puts on their bucket list. Unfortunately, this wonder of the ancient world wasn’t built to sustain the more than 1.2 million tourists that trek to the archeological site annually. Since Peru can’t just close its most popular tourist spot, a new ticketing system was implemented in 2017 to promote preservation.
  • Koh Tachai, Thailand: Like most Thai marine parks, Koh Tachai, an island in Similan National Park, is closed every May through October for the monsoon season. But in 2016, the park didn’t reopen. The beautiful beaches had been overrun with 14 times the number of people experts said the beaches should hold. Officials decided to close the island for rehabilitation, although many fear the damage is irreparable. In addition to problems related to general overcrowding, inexperienced divers — who were more concerned with photographs than their surroundings — damaged the island’s fragile reefs. As of 2019, Koh Tachai is closed to tourists indefinitely.
  • Dubrovnik, Croatia: Although it joined UNESCO’s list of World Heritage Sites back in 1979, Dubrovnik only recently emerged as one of the Mediterranean’s top tourist destinations. Unfortunately, locals claim the Old City’s historic cathedrals, fortresses and buildings have swelled with Disneyland-level crowds — due to the popularity of HBO’s Game of Thrones and the sheer number of cruises it brings in.
  • Boracay, Philippines: Boracay is known for having some of the most beautiful beaches in the world. But those beaches were closed to tourists in 2018 by the president of the Philippines. An estimated 1.7 million travelers visited the island within a 10-month period, raising major infrastructure concerns — namely in terms of sewage treatment.

How Has a Year Without Tourists Impacted These Normally Heavily Trafficked Places?

Cruises were one of the first aspects of the travel industry to shut down in 2020. In fact, the Centers for Disease Control and Prevention (CDC) found that between February 3 and March 13 roughly 200 COVID-19 cases in the U.S. were linked to cruise ship passengers. Soon enough, halts on air travel and widespread lockdowns followed.

methods travelling salesman problem

In Venice, a city that’s usually visited by upwards of 32,000 cruise ship passengers a day, the pandemic has completely changed the day-to-day energy of life there. “Everyday life is a lot more pleasant without the congestion created by the crowds of tourists that came in large groups,” Venice resident Jane da Mosto told CNN Travel .

Of course, that calmer way of life comes at a cost financially. The reprieve from tourists has had that same dual impact the world over. Now, in light of the pandemic, only 75 people are allowed in Machu Picchu at a time, which translates to just under 700 visitors a day. That’s hundreds less than the norm — and, while it’s better for the ancient site, the financial impact will certainly be felt. While experts predict that the travel industry will bounce back, COVID-19 has definitely upset the industry’s stability — largely because the pandemic, and various countries’ reactions to it, are so unpredictable.

Still, some see the pandemic as a disruption to a vicious, seemingly unbreakable cycle. With overtourism, governments often make tradeoffs to keep the cash flowing in, only to scramble for solutions to restore environments and structures or appease upset locals. With this in mind, World Politics Review brings up an interesting question: “Should business-as-usual be salvaged at any cost, or is now the chance to create a smaller, slower and more sustainable model of global tourism?” While the COVID-19 pandemic may have only put a temporary pause on tourism, the pause itself could be a chance to recalibrate, to figure out a way to end overtourism once and for all.


methods travelling salesman problem

Algorithms for the Travelling Salesman Problem

Illustration showing a black model car sitting on a terrain map of northern Europe.

The Traveling Salesman Problem (TSP) is the challenge of finding the shortest path or shortest route for a salesperson to take, given a starting point, a number of cities (nodes), and optionally an ending point. It is a well-known algorithmic problem in the fields of computer science and operations research, with important real-world applications for logistics and delivery businesses.

There are obviously a lot of different routes to choose from, but finding the best one—the one that will require the least distance or cost—is what mathematicians and computer scientists have spent decades trying to solve.

It’s much more than just an academic problem. Finding more efficient routes using route optimization algorithms increases profitability for delivery businesses, and reduces greenhouse gas emissions because it means less distance traveled.

In theoretical computer science, the TSP has commanded so much attention because it’s so easy to describe yet so difficult to solve. The TSP is known to be a combinatorial optimization problem that’s an NP-hard problem, which means that the number of possible solution sequences grows exponential with the number of cities. Computer scientists have not found any algorithm that can solve this problem in polynomial time, and therefore rely on approximation algorithms to try numerous permutations and select the shortest route with the minimum cost.

A random scattering of 22 black dots on a white background.

The main problem can be solved by calculating every permutation using a brute force approach and selecting the optimal solution. However, as the number of destinations increases, the corresponding number of roundtrips grows exponentially and surpasses the capabilities of even the fastest computers. With 10 destinations, there can be more than 300,000 roundtrip permutations. With 15 destinations, the number of possible routes could exceed 87 billion.

For larger real-world travelling salesman problems, when manual methods such as Google Maps Route Planner or Excel route planner no longer suffice, businesses rely on approximate solutions that are sufficiently optimized by using fast tsp algorithms that rely on heuristics. Finding the exact optimal solution using dynamic programming is usually not practical for large problems.

The random dots are now joined by one line that forms a continuous loop.

Three popular Travelling Salesman Problem Algorithms

Here are some of the most popular solutions to the Travelling Salesman Problem:

1. The brute-force approach

The Brute Force approach, also known as the Naive Approach, calculates and compares all possible permutations of routes or paths to determine the shortest unique solution. To solve the TSP using the Brute-Force approach, you must calculate the total number of routes and then draw and list all the possible routes. Calculate the distance of each route and then choose the shortest one—this is the optimal solution. 

This is only feasible for small problems, rarely useful beyond theoretical computer science tutorials.

2. The branch and bound method

The branch and bound algorithm starts by creating an initial route, typically from the starting point to the first node in a set of cities. Then, it systematically explores different permutations to extend the route one node at a time. Each time a new node is added, the algorithm calculates the current path's length and compares it to the optimal route found so far. If the current path is already longer than the optimal route, it "bounds" or prunes that branch of the exploration, as it would not lead to a more optimal solution.

This pruning is the key to making the algorithm efficient. By discarding unpromising paths, the search space is narrowed down, and the algorithm can focus on exploring only the most promising paths. The process continues until all possible routes are explored, and the shortest one is identified as the optimal solution to the traveling salesman problem. Branch and bound is an effective greedy approach for tackling NP-hard optimization problems like the travelling salesman problem.

3. The nearest neighbor method

To implement the Nearest Neighbor algorithm, we begin at a randomly selected starting point. From there, we find the closest unvisited node and add it to the sequencing. Then, we move to the next node and repeat the process of finding the nearest unvisited node until all nodes are included in the tour. Finally, we return to the starting city to complete the cycle.

While the Nearest Neighbor approach is relatively easy to understand and quick to execute, it rarely finds the optimal solution for the traveling salesperson problem. It can be significantly longer than the optimal route, especially for large and complex instances. Nonetheless, the Nearest Neighbor algorithm serves as a good starting point for tackling the travelling salesman problem and can be useful when a quick and reasonably good solution is needed.

This greedy algorithm can be used effectively as a way to generate an initial feasible solution quickly, to then feed into a more sophisticated local search algorithm, which then tweaks the solution until a given stopping condition.  ‍

How route optimization algorithms work to solve the Travelling Salesman Problem.

Academic tsp solutions.

Academics have spent years trying to find the best solution to the Travelling Salesman Problem The following solutions were published in recent years:

  • Machine learning speeds up vehicle routing : MIT researchers apply Machine Learning methods to solve large np-complete problems by solving sub-problems.
  • Zero Suffix Method : Developed by Indian researchers, this method solves the classical symmetric TSP. 
  • Biogeography‐based Optimization Algorithm : This method is designed based on the animals’ migration strategy to solve the problem of optimization. 
  • Meta-Heuristic Multi Restart Iterated Local Search (MRSILS): The proponents of this research asserted that the meta-heuristic MRSILS is more efficient than the Genetic Algorithms when clusters are used. 
  • Multi-Objective Evolutionary Algorithm : This method is designed for solving multiple TSP based on NSGA-II. 
  • Multi-Agent System : This system is designed to solve the TSP of N cities with fixed resource. 

Real-world TSP applications

Despite the complexity of solving the Travelling Salesman Problem, it still finds applications in all verticals. 

For example, TSP solutions can help the logistics sector improve efficiency in the last mile. Last mile delivery is the final link in a supply chain, when goods move from a transportation hub, like a depot or a warehouse, to the end customer. Last mile delivery is also the leading cost driver in the supply chain. It costs an average of $10.1, but the customer only pays an average of $8.08 because companies absorb some of the cost to stay competitive. So bringing that cost down has a direct effect on business profitability.  

The same field of dots from the last images, now in three groups each joined by a single continuous loop. The three loops meet in the middle so that the image looks almost like a flower with three oddly-shaped petals.

Minimizing costs in last mile delivery is essentially in last mile delivery is essentially a Vehicle Routing Problem (VRP). VRP, a generalized version of the travelling salesman problem, is one of the most widely studied problems in mathematical optimization. Instead of one best path, it deals with finding the most efficient set of routes or paths. The problem may involve multiple depots, hundreds of delivery locations, and several vehicles. As with the travelling salesman problem, determining the best solution to VRP is NP-complete.

Real-life TSP and VRP solvers

While academic solutions to TSP and VRP aim to provide the optimal solution to these NP-hard problems, many of them aren’t practical when solving real world problems, especially when it comes to solving last mile logistical challenges.

That’s because academic solvers strive for perfection and thus take a long time to compute the optimal solutions – hours, days, and sometimes years. If a delivery business needs to plan daily routes, they need a route solution within a matter of minutes. Their business depends on delivery route planning software so they can get their drivers and their goods out the door as soon as possible. Another popular alternative is to use Google maps route planner .

Real-life TSP and VRP solvers use route optimization algorithms that find a near-optimal solutions in a fraction of the time, giving delivery businesses the ability to plan routes quickly and efficiently.

If you want to know more about real-life TSP and VRP solvers, check out the resources below 👇

Route Optimization API - TSP Solver

Route Optimization API - VRP Solver

Portrait of Marc Kuo

Frequently Asked Questions

Related articles.

Liked this article? See below for more recommended reading!

A man wearing a red T-shirt with the word "Delivery" across the front stands at the open door of a van. He is holding a small package and looking at his watch.

Solving the Vehicle Routing Problem (2023)

Illustration. A woman sits in front of a large computer screen showing a stylized representation of optimized routes.

What Is Route Optimization?

Decorative graphic repeating the post title with a Google Maps screenshot.

How To Optimize Multi-Stop Routes With Google Maps (2023)

  • Work With Us

baobab soluciones

Three different methods to solve the travelling salesman problem

  • Post author: baobab
  • Post published: 1 Oct, 2020
  • Post category: Algorithm

The travelling salesman

The travelling salesman problem

The travelling salesman problem (TSP) consists on finding the shortest single path that, given a list of cities and distances between them, visits all the cities only once and returns to the origin city.

Its origin is unclear. A German handbook for the travelling salesman from 1832 mentions the problem and includes example tours across Germany and Switzerland, but it does not cover its mathematics.

The first mathematical formulation was done in the 1800s by W.R. Hamilton and Thomas Kirkman. Hamilton’s icosian game was a recreational puzzle based on finding a Hamiltonian cycle, which is actually a solution to the TSP problem in a graph.

The TSP can be formulated as an integer linear program. Although several formulations are known to solve this problem, two of them are the most prominent: the one proposed by Miller, Tucker and Zemlin, and the one proposed by Dantzig, Fulkerson and Johnson.

These methods can theoretically return an optimal solution to the problem but as this is considered an NP-hard problem, they can be too expensive both in computation power and time.

In order to obtain good solutions in a shorter time, a lot of effort has been made to try and solve this problem with a variety of heuristic methods. Out of this whole group of heuristics, we would like to highlight those inspired in biology: Ant Colony Optimization (ACO, which we talked about before here ) and Genetic Algorithms (GA).

Integer Linear programme

As we mentioned there are two main formulations for the TSP, the proposed Miller, Tucker and Zemlin (MTZ) and the Dantzig, Fulkerson and Johnson (DFJ). Although the DFJ formulation is stronger, the MTZ formulation can be useful.

MTZ formulation

The mathematical formulation proposed by Miller, Tucker and Zemlin is as follows:

methods travelling salesman problem

Using this set, the two variables and the parameter we can then formulate the problem as:

\[min \sum_{i=1}^{n}\sum_{j\neq i,j=1}^{n}c_{ij}x_{ij}\]

Subject to:

methods travelling salesman problem

The first and second equations enforce the type of the different variables, the third and fourth equations ensure that each node is reached and departed only once, while the last two equations enforce that only one route crosses all the nodes.

DFJ formulation


The first three equations are the same as in the previous formulation, and the new constraint (last one) ensures that there are no sub-tours, so that the solution returned is a single tour and not the combination of smaller tours. Because this leads to an exponential number of possible constraints, in practice it is solved with delayed column generation.

In the following graph we can see the optimal solution for a 100-node problem.

Optimal solution for the 100-node travelling salesman problem using DFJ formulation

Ant colony optimization

Also known as Ant Colony System (ACS) or Ant System (AS) , it is a probabilistic technique or heuristic used to solve problems that can be reduced to finding good paths in graphs. This method was initially proposed by Marco Dorigo in 1992 in his PhD thesis.

In the following animation it can be seen how this heuristic works for a problem and evolves improving the solution over time.

In the animation the red shadows represent the amount of pheromones deposited by the ants during the calculations.

Genetic algorithm

Genetic algorithms (GA) are heuristics inspired by the evolution process of living things. Each solution is a chromosome composed by genes which represent the different values of the variables of the solution.

Starting with an initial population, we can make the solutions “evolve” over iterations. The process consists in selecting the best half of the population from which we randomly pick pairs of chromosomes (solutions) for mating. In these mating we interchange genes from both solutions to generate new solutions (children).

After the mating process we randomly apply mutations in the resulting children in order to further explore the solution space.

Finally we select the best 50 individuals from the population (the initial plus the children) and continue the process until we converge into a solution.

In the following animation we can see how the genetic algorithm evolves for the same 100-point problem.

As it can be seen in the graphs above each heuristic provides a solution to the problem, although some better than others. When we test these three methods in more datasets we can find the following results:

The performance is calculated as the deviation between the solution provided by each method and the best solution found for that instance.

In very small instances all methods reach the same solution but as the instances get bigger the heuristics start to deviate from the best solution found by the integer linear programme. Although the genetic algorithm shows a larger deviation from the optimal solution, it can still provide a solution within a shorter time than the other methods. Probably, if we were to increase the population in order to better explore the solution space we could get better results without sacrificing processing time.

ACO is the heuristic (and the one exclusively devised for this problem) that can keep with the exact model, but it takes longer to arrive at a solution.

To solve the integer linear model we need a mathematical solver , which can be either free or commercial. For this post we used a commercial solver that actually improves the performance exponentially in contrast to the free ones. This advantage is what makes the integer linear problem faster than ACO. If we were to try free software, ACO would provide better solutions in a shorter time, using an open-source language (python).

If you like solving problems like this, baobab is your place. Check out our job offers.

Check here how these algorithms to solve the Travelling Salesman Problem are developed with python.

By Guillermo González-Santander , Project Manager at baobab.

You Might Also Like

From complex strategic decisions to simple games

From complex strategic decisions to simple games

Ant Colony Optimisation Algorithm

Ant Colony Optimisation Algorithm

This post has one comment.

Pingback: Successfully Implementing Mathematical Optimisation: from Concept to First Results - Numens

Comments are closed.

methods travelling salesman problem

The Travelling Salesman Problem

The Travelling Salesman Problem (TSP) is a classic optimization problem within the field of operations research. It was first studied during the 1930s by several applied mathematicians and is one of the most intensively studied problems in OR.

The TSP describes a scenario where a salesman is required to travel between \(n\) cities. He wishes to travel to all locations exactly once and he must finish at his starting point. The order in which the cities are visited is not important but he wishes to minimize the distance traveled. This problem can be describes as a network, where the cities are represented by nodes which are connected by edges that carry a weight describing the time or distance it takes to travel between cities.

This problem may sounds simple and using a brute force method in theory it is: calculate the time to transverse all possible routes and select the shortest. However, this is extremely time consuming and as the number of cities grows, brute force quickly becomes an infeasible method. A TSP with just 10 cities has 9! or 362,880 possible routes, far too many for any computer to handle in a reasonable time. The TSP is an NP-hard problem and so there is no polynomial-time algorithm that is known to efficiently solve every travelling salesman problem.

Because of how difficult the problem is to solve optimally we often look to heuristics or approximate methods for the TSP to improve speed in finding the solution and closeness to the optimal solution.

The TSP can be divided into two types: the asymmetric travelling salesman problem (ASTP) where the distance from A to B is different to that from B to A and the symmetric travelling salesman problem (STSP) where the distance from A to B is the same as from B to A. For example, the ASTP may arise in cities such as Lancaster where there are one-way roads that make travelling more varied. In this blog I will be focusing on the STSP and outline two of the most basic heuristic algorithms in which to solve them.

Nearest Neighbor Algorithm

One of the simplest algorithms for approximately solving the STSP is the nearest neighbor method, where the salesman always visits the nearest city. The process is as follows:

  • Select a starting city.
  • Find the nearest city to your current one and go there.
  • If there are still cities not yet visited, repeat step 2. Else, return to the starting city.

Using the nearest neighbor algorithm on the below symmetric travelling salesman problem starting at city A, we would then travel to city B followed by D and C, returning back to A. This gives a total length of 18, which in this case is indeed optimal. However, the nearest neighbor algorithm does not always achieve optimality.

methods travelling salesman problem

For example if we change the weight slightly:

methods travelling salesman problem

The solution using the nearest neighbor algorithm starting again at A will result in the Route A -> C -> B -> D -> A, resulting in a route of weight 15. But this is not optimal. If we instead took the route A -> B -> D -> C -> A the weight would be 14, a slight improvement on that obtained by the algorithm. Therefore the algorithm achieved a sub-optimal result.

This algorithm under worst-case performance is \(\mathcal{O}(n^2)\), much better than the brute force method (which is \(\mathcal{O}(n!)\)). It is easy to implement but the greediness of the algorithm does cause it to run quite a high risk of not obtaining the optimal route.

Greedy Approach Algorithm

Before we delve into the next algorithm to tackle the TSP we need the definition of a cycle. A cylce in a network is defined as a closed path between cities in which no city is visited more than once apart from the start and end city. The order of a node or city is the number of edges coming in or out of it.

The greedy algorithm goes as follows:

  • Sort all of the edges in the network.
  • Select the shortest edge and add it to our tour if it does not violate any of the following conditions: there are no cycles in our tour with less than \(n\) edges or increase the degree of any node (city) to more than 2.
  • If we have \(n\) edges in our tour stop, if not repeat step 2.

Applying this algorithm to the STSP in Figure 1, we begin by sorting the edge lengths:

B <-> D = 2, A <-> B = 4, C <-> D =5, A <-> D =6, A <-> C =7, C <-> B =8

We then add the routes B <-> D, A <-> B and C <-> D to our tour without problem. We cannot add A <-> D to our tour as it would create a cycle between the nodes A, B and D and increase the order of node D to 3. We therefore skip this edge and ultimately add edge A <-> C to the tour. This results in the same solution as obtained by the nearest neighbor algorithm.

If we then apply the method to the STSP given in Figure 2 we obtain the optimal route: A -> B -> C -> D -> A. This is an improvement on what was achieved by the nearest neighbor algorithm.

This algorithm is \(\mathcal{O}(n^2\log_2(n))\), higher than that of the nearest neighbor algorithm with only a small improvement in optimality.

References and Further Reading

As said above, these are only two of the most basic algorithms used to obtain an approximate solution to the travelling salesman problem and there are many more sophisticated methods. If you wish to read more about these, I would suggest reading the following two papers:

  • Nilsson, C., (2003). Heuristics for the Traveling Salesman Problem. Linkoping Universit y. Link.
  • Abdulkarim, H., Alshammari, I., (2015). Comparison of Algorithms for Solving Traveling Salesman Problem. International Journal of Engineering and Advanced Technology 4(6).

Design and Analysis of Algorithms Tutorial

  • Design and Analysis of Algorithms
  • Basics of Algorithms
  • DAA - Introduction
  • DAA - Analysis of Algorithms
  • DAA - Methodology of Analysis
  • Asymptotic Notations & Apriori Analysis
  • Time Complexity
  • Master’s Theorem
  • DAA - Space Complexities
  • Divide & Conquer
  • DAA - Divide & Conquer
  • DAA - Max-Min Problem
  • DAA - Merge Sort
  • DAA - Binary Search
  • Strassen’s Matrix Multiplication
  • Karatsuba Algorithm
  • Towers of Hanoi
  • Greedy Algorithms
  • DAA - Greedy Method

Travelling Salesman Problem

  • Prim's Minimal Spanning Tree
  • Kruskal’s Minimal Spanning Tree
  • Dijkstra’s Shortest Path Algorithm
  • Map Colouring Algorithm
  • DAA - Fractional Knapsack
  • DAA - Job Sequencing with Deadline
  • DAA - Optimal Merge Pattern
  • Dynamic Programming
  • DAA - Dynamic Programming
  • Matrix Chain Multiplication
  • Floyd Warshall Algorithm
  • DAA - 0-1 Knapsack
  • Longest Common Subsequence
  • Travelling Salesman Problem | Dynamic Programming
  • Randomized Algorithms
  • Randomized Quick Sort
  • Karger’s Minimum Cut
  • Fisher-Yates Shuffle
  • Approximation Algorithms
  • Vertex Cover Problem
  • Set Cover Problem
  • Travelling Salesperson Approximation Algorithm
  • Sorting Techniques
  • DAA - Quick Sort
  • DAA - Bubble Sort
  • DAA - Insertion Sort
  • DAA - Selection Sort
  • DAA - Shell Sort
  • DAA - Heap Sort
  • DAA - Bucket Sort
  • DAA - Counting Sort
  • DAA - Radix Sort
  • Searching Techniques
  • Searching Techniques Introduction
  • DAA - Linear Search
  • DAA - Interpolation Search
  • DAA - Jump Search
  • DAA - Exponential Search
  • DAA - Fibonacci Search
  • DAA - Sublist Search
  • DAA - Hash Table
  • Graph Theory
  • DAA - Shortest Paths
  • DAA - Multistage Graph
  • Optimal Cost Binary Search Trees
  • Heap Algorithms
  • DAA - Binary Heap
  • DAA - Insert Method
  • DAA - Heapify Method
  • DAA - Extract Method
  • Complexity Theory
  • Deterministic vs. Nondeterministic Computations
  • DAA - Max Cliques
  • DAA - Vertex Cover
  • DAA - P and NP Class
  • DAA - Cook’s Theorem
  • NP Hard & NP-Complete Classes
  • DAA - Hill Climbing Algorithm
  • DAA Useful Resources
  • DAA - Quick Guide
  • DAA - Useful Resources
  • DAA - Discussion
  • Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary

The travelling salesman problem is a graph computational problem where the salesman needs to visit all cities (represented using nodes in a graph) in a list just once and the distances (represented using edges in the graph) between all these cities are known. The solution that is needed to be found for this problem is the shortest possible route in which the salesman visits all the cities and returns to the origin city.

If you look at the graph below, considering that the salesman starts from the vertex ‘a’, they need to travel through all the remaining vertices b, c, d, e, f and get back to ‘a’ while making sure that the cost taken is minimum.


There are various approaches to find the solution to the travelling salesman problem: naïve approach, greedy approach, dynamic programming approach, etc. In this tutorial we will be learning about solving travelling salesman problem using greedy approach.

Travelling Salesperson Algorithm

As the definition for greedy approach states, we need to find the best optimal solution locally to figure out the global optimal solution. The inputs taken by the algorithm are the graph G {V, E}, where V is the set of vertices and E is the set of edges. The shortest path of graph G starting from one vertex returning to the same vertex is obtained as the output.

Travelling salesman problem takes a graph G {V, E} as an input and declare another graph as the output (say G’) which will record the path the salesman is going to take from one node to another.

The algorithm begins by sorting all the edges in the input graph G from the least distance to the largest distance.

The first edge selected is the edge with least distance, and one of the two vertices (say A and B) being the origin node (say A).

Then among the adjacent edges of the node other than the origin node (B), find the least cost edge and add it onto the output graph.

Continue the process with further nodes making sure there are no cycles in the output graph and the path reaches back to the origin node A.

However, if the origin is mentioned in the given problem, then the solution must always start from that node only. Let us look at some example problems to understand this better.

Consider the following graph with six cities and the distances between them −


From the given graph, since the origin is already mentioned, the solution must always start from that node. Among the edges leading from A, A → B has the shortest distance.

graph a to b

Then, B → C has the shortest and only edge between, therefore it is included in the output graph.


There’s only one edge between C → D, therefore it is added to the output graph.


There’s two outward edges from D. Even though, D → B has lower distance than D → E, B is already visited once and it would form a cycle if added to the output graph. Therefore, D → E is added into the output graph.

graph d to e

There’s only one edge from e, that is E → F. Therefore, it is added into the output graph.

graph e to f

Again, even though F → C has lower distance than F → A, F → A is added into the output graph in order to avoid the cycle that would form and C is already visited once.

graph f to a

The shortest path that originates and ends at A is A → B → C → D → E → F → A

The cost of the path is: 16 + 21 + 12 + 15 + 16 + 34 = 114.

Even though, the cost of path could be decreased if it originates from other nodes but the question is not raised with respect to that.

The complete implementation of Travelling Salesman Problem using Greedy Approach is given below −

Kickstart Your Career

Get certified by completing the course

  • DSA for Beginners
  • DSA Tutorial
  • Data Structures
  • Linked List
  • Dynamic Programming
  • Binary Tree
  • Binary Search Tree
  • Divide & Conquer
  • Mathematical
  • Backtracking
  • Branch and Bound
  • Pattern Searching

methods travelling salesman problem

  • Explore Our Geeks Community
  • What is memoization? A Complete tutorial
  • Dynamic Programming (DP) Tutorial with Problems
  • Tabulation vs Memoization
  • Optimal Substructure Property in Dynamic Programming | DP-2
  • Overlapping Subproblems Property in Dynamic Programming | DP-1
  • Steps for how to solve a Dynamic Programming Problem

Advanced Topics

  • Bitmasking and Dynamic Programming | Set 1 (Count ways to assign unique cap to every person)
  • Digit DP | Introduction
  • Sum over Subsets | Dynamic Programming

Easy problems in Dynamic programming

  • Count number of coins required to make a given value (Coin Change II)
  • Subset Sum Problem
  • Introduction and Dynamic Programming solution to compute nCr%p
  • Cutting a Rod | DP-13
  • Painting Fence Algorithm
  • Longest Common Subsequence (LCS)
  • Longest Increasing Subsequence (LIS)
  • Longest subsequence such that difference between adjacents is one
  • Maximum size square sub-matrix with all 1s
  • Min Cost Path | DP-6
  • Longest Common Substring (Space optimized DP solution)
  • Count ways to reach the nth stair using step 1, 2 or 3
  • Count Unique Paths in matrix
  • Unique paths in a Grid with Obstacles

Medium problems on Dynamic programming

  • 0/1 Knapsack Problem
  • Printing Items in 0/1 Knapsack
  • Unbounded Knapsack (Repetition of items allowed)
  • Egg Dropping Puzzle | DP-11
  • Word Break Problem | DP-32
  • Vertex Cover Problem (Dynamic Programming Solution for Tree)
  • Tile Stacking Problem
  • Box Stacking Problem | DP-22
  • Partition problem | DP-18

Travelling Salesman Problem using Dynamic Programming

  • Longest Palindromic Subsequence (LPS)
  • Longest Common Increasing Subsequence (LCS + LIS)
  • Find all distinct subset (or subsequence) sums of an array
  • Weighted Job Scheduling
  • Count Derangements (Permutation such that no element appears in its original position)
  • Minimum insertions to form a palindrome | DP-28
  • Ways to arrange Balls such that adjacent balls are of different types

Hard problems on Dynamic programming

  • Palindrome Partitioning
  • Word Wrap Problem
  • The Painter's Partition Problem
  • Program for Bridge and Torch problem
  • Matrix Chain Multiplication | DP-8
  • Printing brackets in Matrix Chain Multiplication Problem
  • Maximum sum rectangle in a 2D matrix | DP-27
  • Maximum profit by buying and selling a share at most k times
  • Minimum cost to sort strings using reversal operations of different costs
  • Count of AP (Arithmetic Progression) Subsequences in an array
  • Introduction to Dynamic Programming on Trees
  • Maximum height of Tree when any Node can be considered as Root
  • Longest repeating and non-overlapping substring
  • Discuss(40+)

Travelling Salesman Problem (TSP):  

Given a set of cities and the distance between every pair of cities, the problem is to find the shortest possible route that visits every city exactly once and returns to the starting point. Note the difference between Hamiltonian Cycle and TSP. The Hamiltonian cycle problem is to find if there exists a tour that visits every city exactly once. Here we know that Hamiltonian Tour exists (because the graph is complete) and in fact, many such tours exist, the problem is to find a minimum weight Hamiltonian Cycle. 


For example, consider the graph shown in the figure on the right side. A TSP tour in the graph is 1-2-4-3-1. The cost of the tour is 10+25+30+15 which is 80. The problem is a famous NP-hard problem. There is no polynomial-time know solution for this problem. The following are different solutions for the traveling salesman problem. 

Naive Solution:  

1) Consider city 1 as the starting and ending point.

2) Generate all (n-1)! Permutations of cities. 

3) Calculate the cost of every permutation and keep track of the minimum cost permutation. 

4) Return the permutation with minimum cost. 

Time Complexity: Θ(n!) 

Dynamic Programming:  

Let the given set of vertices be {1, 2, 3, 4,….n}. Let us consider 1 as starting and ending point of output. For every other vertex I (other than 1), we find the minimum cost path with 1 as the starting point, I as the ending point, and all vertices appearing exactly once. Let the cost of this path cost (i), and the cost of the corresponding Cycle would cost (i) + dist(i, 1) where dist(i, 1) is the distance from I to 1. Finally, we return the minimum of all [cost(i) + dist(i, 1)] values. This looks simple so far. 

Now the question is how to get cost(i)? To calculate the cost(i) using Dynamic Programming, we need to have some recursive relation in terms of sub-problems. 

Let us define a term C(S, i) be the cost of the minimum cost path visiting each vertex in set S exactly once, starting at 1 and ending at i . We start with all subsets of size 2 and calculate C(S, i) for all subsets where S is the subset, then we calculate C(S, i) for all subsets S of size 3 and so on. Note that 1 must be present in every subset.

Below is the dynamic programming solution for the problem using top down recursive+memoized approach:-

For maintaining the subsets we can use the bitmasks to represent the remaining nodes in our subset. Since bits are faster to operate and there are only few nodes in graph, bitmasks is better to use.

For example: –  

10100 represents node 2 and node 4 are left in set to be processed

010010 represents node 1 and 4 are left in subset.

NOTE:- ignore the 0th bit since our graph is 1-based

Time Complexity : O(n 2 *2 n ) where O(n* 2 n) are maximum number of unique subproblems/states and O(n) for transition (through for loop as in code) in every states.

Auxiliary Space: O(n*2 n ), where n is number of Nodes/Cities here.

For a set of size n, we consider n-2 subsets each of size n-1 such that all subsets don’t have nth in them. Using the above recurrence relation, we can write a dynamic programming-based solution. There are at most O(n*2 n ) subproblems, and each one takes linear time to solve. The total running time is therefore O(n 2 *2 n ). The time complexity is much less than O(n!) but still exponential. The space required is also exponential. So this approach is also infeasible even for a slightly higher number of vertices. We will soon be discussing approximate algorithms for the traveling salesman problem.

Next Article: Traveling Salesman Problem | Set 2  




Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above

Solve DSA problems on GfG Practice.

  • DSA in Java
  • DSA in Python
  • DSA in JavaScript

Please Login to comment...

Similar read thumbnail

  • lokeshpotta20
  • serjeelranjan
  • sagartomar9927
  • tapeshdua420
  • akashcherukuri007
  • akshaytripathi19410

Please write us at [email protected] to report any issue with the above content

Improve your Coding Skills with Practice


US6904421B2 - Methods for solving the traveling salesman problem - Google Patents

  • USPTO PatentCenter
  • USPTO Assignment
  • Global Dossier

methods travelling salesman problem


  • G06N3/00 — Computing arrangements based on biological models
  • G06N3/12 — Computing arrangements based on biological models using genetic models
  • G06N3/126 — Evolutionary algorithms, e.g. genetic algorithms or genetic programming
  • G06Q10/00 — Administration; Management
  • G06Q10/04 — Forecasting or optimisation specially adapted for administrative or management purposes, e.g. linear programming or "cutting stock problem"
  • G06Q10/047 — Optimisation of routes or paths, e.g. travelling salesman problem


Claims ( 38 ), priority applications (1), applications claiming priority (1), publications (2), id=25289294, family applications (1), country status (1), cited by (20), families citing this family (27), citations (10).

  • 2001-04-26 US US09/843,192 patent/US6904421B2/en not_active Expired - Lifetime

Patent Citations (11)

Non-patent citations (7), cited by (29), also published as, similar documents, legal events.


  1. PPT

    methods travelling salesman problem

  2. Traveling Salesman Problem

    methods travelling salesman problem

  3. 😊 Travelling salesman problem 5 cities. The Traveling Salesman Problem

    methods travelling salesman problem

  4. Travelling salesman problem in c

    methods travelling salesman problem

  5. PPT

    methods travelling salesman problem

  6. PPT

    methods travelling salesman problem


  1. Travelling Salesman Problem

  2. Traveling Salesman Problem

  3. Traveling Salesman Problem| NP- Class Problem

  4. 1.5 Travelling Salesman Problem

  5. Travelling Salesman problem #cseguru #shorts #shorts_video #shortsfeed #algorithm #cseguruadavideos

  6. 2.1.4. Travelling Salesman Algorithm


  1. What Is a Computation Method in Math?

    In math, a computation method is used to find an answer in regards to any given problem. The most common computation methods make up the majority of basic math functions including addition, subtraction, multiplication and division.

  2. No Sound? Try These Effective Methods to Fix Your Computer’s Audio

    Are you facing issues with the sound on your computer? Having audio problems can be frustrating, especially if you rely on your computer for work or entertainment. But don’t worry, there are several effective methods you can try to fix the ...

  3. How Has a Year Without Tourists Impacted the Overtourism Problem?

    All press is good press — until that press goes too well. Although the Netherlands’ beautiful, canal-filled city of Amsterdam garners about $91.5 billion a year through tourism, the city and its residents feel more overwhelmed than grateful...

  4. Algorithms for the Travelling Salesman Problem

    The Traveling Salesman Problem (TSP) is the challenge of finding the shortest path or shortest route for a salesperson to take, given a starting point

  5. Travelling salesman problem

    The best-known method in this family is the Lin–Kernighan method (mentioned above as a misnomer for 2-opt). Shen Lin and Brian Kernighan first published their

  6. Three different methods to solve the travelling salesman problem

    The first and second equations enforce the type of the different variables, the third and fourth equations ensure that each node is reached and

  7. A Method for Solving Traveling-Salesman Problems

    The traveling-salesman problem is a generalized form of the simple prob- lem to find the smallest closed loop that connects a number of points in a.

  8. A Labelling Method for the Travelling Salesman Problem

    The travelling salesman problem (TSP) is a problem whereby a finite number of nodes are supposed to be visited exactly once, one after the other, in such a

  9. How to Solve the Traveling Salesman Problem

    The traveling salesman problem is a classic problem in combinatorial optimization. This problem is to find the shortest path that a salesman

  10. Different approaches to Travelling Salesman Problem

    The objective of this thesis is to compare 8 different algorithms that solve the. Traveling Salesman Problem with their own particular method . Those will be

  11. The Travelling Salesman Problem

    The TSP describes a scenario where a salesman is required to travel between n cities. He wishes to travel to all locations exactly once and he

  12. Travelling Salesman Problem

    The travelling salesman problem is a graph computational problem where the salesman needs to visit all cities (represented using nodes in a graph) in a list

  13. Travelling Salesman Problem using Dynamic Programming

    Travelling Salesman Problem using Dynamic Programming · 1) Consider city 1 as the starting and ending point. · 2) Generate all (n-1)! Permutations

  14. Methods for solving the traveling salesman problem

    Solving a Traveling Salesman Problem (TSP) by selecting a set of locations to visit, selecting a starting point and an ending point from the set of