0% found this document useful (0 votes)
99 views

Dynamic Programming TSP

The document describes an algorithm for solving the traveling salesperson problem (TSP) using dynamic programming. It represents the graph and precomputes shortest path lengths. The algorithm computes the optimal tour length by taking the minimum, over all vertices j, of the weight from vertex 1 to j plus the previously computed shortest path from j to the remaining vertices. The time complexity is O(n22n) and space complexity is O(n2n).
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Dynamic Programming TSP

The document describes an algorithm for solving the traveling salesperson problem (TSP) using dynamic programming. It represents the graph and precomputes shortest path lengths. The algorithm computes the optimal tour length by taking the minimum, over all vertices j, of the weight from vertex 1 to j plus the previously computed shortest path from j to the remaining vertices. The time complexity is O(n22n) and space complexity is O(n2n).
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Dynamic Programming-TSP

V. Balasubramanian

The traveling sales person problem


Tour (Hamilton circuit): a path from a vertex to itself that
passes through each of the other vertices exactly once
Optimal tour: such a path of minimum length
Brute force algorithm is
(n-1)(n-2)1 = (n-1)!
Principle of optimality applies

`
`
`
`

Algorithms (eadeli@iust.ac.ir)

Representation of the graph

Algorithms (eadeli@iust.ac.ir)

Preparation
Let D[vi][A] = length of a shortest path from vi to v1
passing through each vertex in A exactly once
Compute D[v2][A] when A = {v3} and A = {v3, v4}

`
`

Algorithms (eadeli@iust.ac.ir)

The algorithm
Length of an optimal tour =

Minimum (W [1][ j ] + D[v ][V {v , v }])


j

2 j n

In general for i 1 and vi not in A

D[vi ][ A] = Minimum (W [i ][ j ] + D[v j ][ A {v j}])


j:v j A
D[vi ][ ] = W [i ][1]

Algorithms (eadeli@iust.ac.ir)

if

Compute the optimal tour

Algorithms (eadeli@iust.ac.ir)

The Algorithm
Algorithm 3.11: The Dynamic Programming Algorithm for the Traveling Salesperson Problem
void travel (int n, const number W[][], index P[][], number& minlength)
{
index i, j, k;
number D[1..n][subset of V - {v1}];
for (i = 2; i <= n; i++) D[i][] = W[i][1];
for (k = 1; k <= n - 2; k++)
for (all subsets A V - {v1} containing k vertices)
for (i such that i 1 and vi is not in A){
D[i][A] = minimum (W[i][j] + D[j][A - {vj}]);
j: vj A
P[i][A] = value of j that gave the minimum;
}
D[1][V - {v1}] = minimum (W[1][j] + D[j][V - {v1, vj}]);
2jn
P[1][V - {v1}] = value of j that gave the minimum;
minlength = D[1][V - {v1}];
}
Algorithms (eadeli@iust.ac.ir)

A Theorem
`

For all n 1

n
n 1
k = n 2

k =1 k
n

Algorithms (eadeli@iust.ac.ir)

Every-case time complexity


Basic operation: the instructions executed for each value
of vj
n, the number of vertices in the graph
Time complexity
T(n) = (n-1)(n-2)2n-3 (n22n)
Memory complexity:
M(n) = 2 n2n-1 = n2n (n2n)

`
`
`

Algorithms (eadeli@iust.ac.ir)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy