hw2solns - 15-750 Graduate Algorithms Spring 2009Miller and...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 15-750 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 minimizesn-1i=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 super-exponential number of different orderings((n-1)!, to be precise), so this algorithm takes not just super-polynomial, but also super-exponentialtime! 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)oif|S| 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 on|S|that 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 of|S|is trivially true:T({1},1)is. Assume inductively that the claim holdsfor allSandtsuch that|S|=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)o-d(t,i)T(S\ {i},i),which is a contradiction to the optimality ofT(S\ {i},i).15-750 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.

Page1 / 7

hw2solns - 15-750 Graduate Algorithms Spring 2009Miller and...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online