Np completeness
-
Upload
muhammad-saim -
Category
Technology
-
view
424 -
download
0
Transcript of Np completeness
NP-CompletenessDesign and Analysis of AlgorithmMuhammad Saim (BSCS/S13/0104)
Introduction• A problem is said to be polynomial
if there exists an algorithm that solves the problem in time
• T(n)=O(nc), where c is a constant.
• Examples of polynomial problems:– Sorting: O(n log n) = O(n2)– All-pairs shortest path: O(n3)– Minimum spanning tree: O(N log N)= O(N2)
Intro (continued)
• The world of computation can besubdivided into three classes:
Polynomial problems (P)Exponential problems (E)Intractable (non-computable) problems (I)
Even More Intro
• we know how to solve exponentially,• we don't know how to solve polynomially, and• we don't know if they can be solved polynomially at
all
There is a very large and important class of problems that
NP-Completeness• Defination:
A problem is said to be Nondeterministically Polynomial (NP) if we can find a nodeterminsitic Turing machine that can solve the problem in a polynomial number of nondeterministic moves.
Another DefinitionA problem is said to be NP if
• its solution comes from a finite set of possibilities, and
• it takes polynomial time to verify the correctness of a candidate solution
AND Another• A problem is said to be NP if there
exists an NP algorithm for it.
begin /* The following for-loop is the guessing stage*/ for i=1 to N do X[i] := choose(i); endfor /* Next is the verification stage */ Write code that does not use "choose" and that verifies if X[1:N] is a correct solution to the problem.
end
NP-Completeness
• Good news: such-and-such a problem can be solvedquickly
• Bad news: evidence that many important problems can't be
solved quickly
Why Should We Care?• The sad news is these NP-complete
problems really come up all the time.
They are Hard:• stop beating your head against a wall & do
something better.
The BIG PROBLEM
IS P=NP??That’s
Complexity Theory
So complex that many /ˌθɪərəˈtɪʃ(ə)n/ say it is false.
N?? P?? NP??What are you talking about?
• N= Non-deterministic• P= Polynomial• NP= Non-deterministic Polynomial
(you guessed it)
Remember the Non-deterministic Turing machine I talked about earlier?
Come on it was only 5 slides back.
Slide 5Now you remember
THE SOLUTIONAmazing Computer can do what normal Computers can't
• It is not a Super Computer (they are just very fast normal computers)• It is really a "Non-deterministic“ Computer
• We can solve a problem in P time using this “Amazing Compuer”
RESULT:
Stop staring and listen
• N" computer can also do anything a normal computer can, we know that "P" problems are also in "NP".
• The easy problems are in "P" (and "NP"), but the really hard ones are *only* in "NP", and they are called "NP-complete".
TADA!!
IF we really had such computers…
One more thing
• it is believed that if anyone could *ever* solve an "NP-Complete" problem in "P" time
• *all* "NP-complete" problems could also be solved that way by using the same method
More talking
• In computational complexity theory, the Cook–Levin theorem, also known as Cook's theorem, states that the Boolean satisfiability problem is NP-complete. That is, any problem in NP can be reduced in polynomial time by a deterministic Turing machine to the problem of determining whether a Boolean formula is satisfiable.
Blah…
Blah…
Blah…
BORING
Lets do it…
• Travelling Salesman Problem
• Imagine you need to visit 5 cities on your sales tour.
• You know all the distances.• Which is the shortest round-trip to follow?
ABCEDA? ADECBA?
• An obvious solution is to check all possibilities.
Lets take a brake now
So what do you think?Why did I choose “The traveling salesman” Problem?
Is it easy?Or because we already did it in class?
Actually NO!
Because….
There is a movie on it… I bet you didn’t know!
Back to work
• this only works for small problems
• If you add a new city it needsto be tried out in every previouscombination
• So this method takes “factorial time": t = n!
Actually t = (n-1)! but it is still factorial.
Sounds easy, right?
• Lets say the program could solve a 20-city problem in 1 second, then
• a 21-city problem would take about 21 seconds to solve.
• And a 22-city problem would take about 462 seconds (over 7 minutes),
• and a 30-city problem would take 3 Million Years. Ouch!
Thanks to “Richard E. Bellman”
• We have Dynamic programming• but the best still take "exponential time":
t = 2n
But if we had the “Amazing Computer”
• So a program that solved 20 cities in 1 second
• would take about 10 minutes to solve a 30-city
• problem and a 60-city problem would take 35,000 Years.
And…
We could create multiple copies of theearlier sub-problems
solving each of those sub-problems justonce, and storing their solutions
In this way we can check for solutions of similar problems without repeating the actual process
Hungry for more?
Check out:
Computers and Intractibility:A guide to the theory of NP-completenessMichael R. Garey and David S. JohnsonW. H. Freeman, 1979.
In the End
Method to solve a NP-complete problem:
1. look for it in Garey and Johnson
2. find as similar a problem as you can in Garey and Johnson
3. you could always go back to the methods in Garey and Johnson