The travelling salesman problem is a classical mathematical problem solved through graph theory, actually the problem was – How can a Travelling salesman starting from one city can return to same city while travelling various city at Shortest route while  travelling?

Travelling Salesman Problem-EssayCorp

According to the graph theory, this requirement makes a closed graph or it can be termed as Hamilton Cycle ( A cycle is tour in graph where initial vertex is repeated at end) and this particular graph is called Hamilton Graph.

Travelling Salesman Problem-EssayCorp

Above figures represent two routes starting from one and returning back at 1 , it is clearly it is selection of route that makes complete short tour.

The Travelling Salesman Problem (also known as TSP) is a algorithmic problem in the field of computer science.


“Solving Travelling Salesman Problem through Dynamic Programming”

The  rule for writing the  Dynamic Programming is as follows-

F(Sn, DN) = RN+ FN-1*(Sn-1, Dn-1)


F (SN, DN ) = Return on n-stage of the value input

SN= Initial Conditions

SN-1 = Final Condition

DN= Decision made at each stage.

DN-1= Decision made at final stage

RN= Return function

FN= Final function



  • Determine the basis of Hamilton graph using-


 f(i, ∅)=∁i,1;2≤i≤n)

  • Calculate f(i,s) using      


  • By obtained results of previous step calculate the equation of a recursive relationship


  • After calculating above step the recursive relationship will give shortest rule.



Travelling Salesman Problem

Implementation in C++




using namespace std;

int c = 0,cost = 999;

int graph[4][4] = { {0, 20, 25, 30},

                   {20, 0, 45, 35},

                   {25, 45, 0, 40},

                   {30, 35, 40, 0}


void swap (int *a, int *b)


   int temp;

   temp = *a;

   *a = *b;

   *b = temp;


void copy_array(int *x, int n)


   int i, sum = 0;

   for(i = 0; i <= n; i++)


       sum += graph[x[i % 4]][x[(i + 1) % 4]];


   if (cost > sum)


       cost = sum;



void permute(int *x, int i, int n)


  int j, k;

  if (i == n)


       copy_array(a, n);




       for (j = i; j <= n; j++)


           swap((x + i), (x + j));

           permute(x, i + 1, n);

           swap((x + i), (x + j));




int main()


  int i, j;

  int a[] = {0, 1, 2, 3};  

  permute(a, 0, 3);

  cout<<“minimum cost:”<<cost<<endl;




Importance of Travelling Salesman Problem

The Travelling Salesman problem is best for calculating optimal route. It is used in many practical solutions. Not only minimum route the shortest timing can also be calculated. It is used in logistic planning and goods allocation. Still it has its importance in research too.



Category :
Publish Date :
    Social Sharing