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 577x 1x 2x 1x 1x 2x 3x 3C 1 C 2 C 3Figure 17.6 The graph generated from boolean expression B = (x 1 +x 2 )·(x 1 +x 2 +x 3 )·(x 1 +x 3 ). Literals from the first clause are labeled C1, <strong>and</strong> literals fromthe second clause are labeled C2. There is an edge between every two pairs ofvertices except when both vertices represent instances of literals from the sameclause, or a negation of the same variable. Thus, the vertex labeled C1 : y 1 doesnot connect <strong>to</strong> the vertex labeled C1 : y 2 (because they are literals in the sameclause) or the vertex labeled C2 : y 1 (because they are opposite values for thesame variable).17.2.3 Coping with N P-Complete ProblemsFinding that your problem is N P-complete might not mean that you can just forgetabout it. Traveling salesmen need <strong>to</strong> find reasonable sales routes regardless of thecomplexity of the problem. What do you do when faced with an N P-completeproblem that you must solve?There are several techniques <strong>to</strong> try. One approach is <strong>to</strong> run only small instancesof the problem. For some problems, this is not acceptable. For example, TRAVEL-ING SALESMAN grows so quickly that it cannot be run on modern computers forproblem sizes much over 20 cities, which is not an unreasonable problem size forreal-life situations. However, some other problems in N P, while requiring exponentialtime, still grow slowly enough that they allow solutions for problems of auseful size.Consider the Knapsack problem from Section 16.1.1. We have a dynamic programmingalgorithm whose cost is Θ(nK) for n objects being fit in<strong>to</strong> a knapsack ofsize K. But it turns out that Knapsack is N P-complete. Isn’t this a contradiction?Not when we consider the relationship between n <strong>and</strong> K. How big is K? Input sizeis typically O(n lg K) because the item sizes are smaller than K. Thus, Θ(nK) isexponential on input size.

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

Saved successfully!

Ooh no, something went wrong!