12.07.2015 Views

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

A Practical Introduction to Data Structures and Algorithm Analysis

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Sec. 17.2 Hard Problems 5693EA8224B3 611 1DCFigure 17.4 An illustration of the TRAVELING SALESMAN problem. Fivevertices are shown, with edges between each pair of cities. The problem is <strong>to</strong> visitall of the cities exactly once, returning <strong>to</strong> the start city, with the least <strong>to</strong>tal cost.route would be ABDCEA, with cost 11. The best route for this particular graphwould be ABEDCA, with cost 9.We cannot solve this problem in polynomial time with a guess-<strong>and</strong>-test nondeterministiccomputer. The problem is that, given a c<strong>and</strong>idate cycle, while we canquickly check that the answer is indeed a cycle of the appropriate form, <strong>and</strong> whilewe can quickly calculate the length of the cycle, we have no easy way of knowingif it is in fact the shortest such cycle. However, we can solve a variant of thisproblem cast in the form of a decision problem. A decision problem is simply onewhose answer is either YES or NO. The decision problem form of TRAVELINGSALESMAN is as follows:TRAVELING SALESMAN (2)Input: A complete, directed graph G with positive distances assigned <strong>to</strong>each edge in the graph, <strong>and</strong> an integer k.Output: YES if there is a simple cycle with <strong>to</strong>tal distance ≤ k containingevery vertex in G, <strong>and</strong> NO otherwise.We can solve this version of the problem in polynomial time with a non-deterministiccomputer. The non-deterministic algorithm simply checks all of the possiblesubsets of edges in the graph, in parallel. If any subset of the edges is anappropriate cycle of <strong>to</strong>tal length less than or equal <strong>to</strong> k, the answer is YES; otherwisethe answer is NO. Note that it is only necessary that some subset meet therequirement; it does not matter how many subsets fail. Checking a particular subsetis done in polynomial time by adding the distances of the edges <strong>and</strong> verifyingthat the edges form a cycle that visits each vertex exactly once. Thus, the checkingalgorithm runs in polynomial time. Unfortunately, there are 2 |E| subsets <strong>to</strong> check,so this algorithm cannot be converted <strong>to</strong> a polynomial time algorithm on a regu-

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!