This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 15750 Graduate Algorithms Spring 2009Miller and Dinitz and TangwongsanAssignment 2 Solutions1Traveling Salesman(25 pts.)In thetraveling salesman problemwe are givenncities and all distances between the cities. Atraveling salesman needs to visit all of these cities in order to sell his product, and then return backto the one he started at (which is presumably his home). The goal is to minimize the total distancethe salesman needs to travel. More formally, letCdenote the set of cities we are given, and letd(i,j)denote the distance between cityiand cityj, wherei,jC. Then the goal is to find a bijection(i.e. an ordering)f:{1,2,...,n} Cthat minimizesn1i=1d(f(i),f(i+ 1)) +d(f(n),f(1)).The trivial algorithm for this problem takes examines every possible ordering and returns whicheverhas the minimum total distance. But there are a superexponential number of different orderings((n1)!, to be precise), so this algorithm takes not just superpolynomial, but also superexponentialtime! For this problem we are asking you to design an exponential time algorithm; in particular,you should design an algorithm that runs in timeO(2npoly(n)), wherepoly(n) denotes anypolynomial function ofn.Solution:We use dynamic programming solve this problem. Assume that the cities are numbered from1ton. We will be working the following subproblems: for{1} S[n]andtS, letT(S,t)denotethe total distance of the best tour that visits all the cities inSstarting at city1and ending at cityt.We establish the following:T(S,t) =ifS={1}andt= 1minsS\{t}nT(S\ {t},s) +d(s,t)oifS 2To solve a TSP instance, we compute the tableTand reportmintST([n],t) +d(t,1)as the totaldistance of the optimal tour. The running time of this algorithm isO(2nn2): we need to fill at most2nnentries of the tableT, each of which can be computed inO(n)time (just finding the min). Weshow by induction onSthat the above recurrence actually computes what we defineT(S,t)to be.Claim:T(S,t), as computed by the above recurrence, is the total distance of the best tour that visitsall the cities inSstarting at city1and ending at cityt.Proof.The base case ofSis trivially true:T({1},1)is. Assume inductively that the claim holdsfor allSandtsuch thatS=k. Then, letSof cardinalityk+ 1andtbe given. Suppose for acontradiction thatis a better tour than whatT(S,t)has found. Letibe the cityvisited rightbeforet, and dist()be the distance traveled on the tour. Letbe the same asexcept it stopsright when it visitsi, sodist() =dist()d(t,i)<minsS\{t}nT(S\ {t},s) +d(s,t)od(t,i)T(S\ {i},i),which is a contradiction to the optimality ofT(S\ {i},i).15750 HW 2 Solutions2Since any tour that visits all the cities has to pass city1, it is not difficult to see that we output the totaldistance of the best tour. Finally, to construct an actual ordering of cities, we can trace the tableT,making note of which city attains the minimum for each relevant pair(S,t). This can be accomplished....
View
Full
Document
This document was uploaded on 11/03/2009.
 Spring '09
 Algorithms

Click to edit the document details