0% found this document useful (0 votes)
9 views23 pages

NP Complete Notes

This is the notes of NP completeness theory

Uploaded by

keshavpal583
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views23 pages

NP Complete Notes

This is the notes of NP completeness theory

Uploaded by

keshavpal583
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

NP-Completeness

• NP-completeness is a form of bad news!


– Evidence that many important problems can not be
solved quickly.
• Knowing that they are hard lets you stop beating
your head against a wall trying to solve them…
– Use a heuristic: come up with a method for solving a
reasonable fraction of the common cases.
– Solve approximately: come up with a solution that
you can prove that is close to right.
– Use an exponential time solution: if you really have
to solve the problem exactly and stop worrying about
finding a better solution.
1
Example of Unsolvable Problem
• Halting problem is the problem of determining, from a
description of an arbitrary computer program and an
input, whether the program will finish running, or
continue to run forever.
• Turing discovered in the 1930’s that there are problems
unsolvable by any algorithm.
• The most famous of them is the halting problem
num ← 1
– Given an arbitrary algorithm REPEAT UNTIL (num = 0) {
DISPLAY(num) num ← num + 1
and its input, will that algorithm }

eventually halt, or will it continue


forever in an “infinite loop?”
– Alan Turing proved in 1936

2
Examples of Intractable Problems

3
Class of “P” Problems
• Definition: The Class P
– P is the class of decision problems that are polynomial bounded.
– There exist a deterministic algorithm

• Polynomial-time algorithms
– Worst-case running time is O(nk), for some constant k
• Examples of polynomial time:
– O(n2), O(n3), O(1), O(n lg n)

4
Class of “NP” Problems
• Definition: The Class NP
– NP is the class of decision problems for which there is a
polynomial bounded non-deterministic algorithm.
– The name “NP” comes from “Non-deterministic” polynomial
bounded
– There exist a non-deterministic algorithm
– P NP ?
• Examples of non-polynomial time:
– O(2n), O(nn), O(n!)
is TSP ∊ NP ?
Guess a tour, check every city visited exactly once
check return to start & total distance <B
all done in O(n) so TSP ∊ NP
5
3SAT -Problem
o Goal of Verification algorithm is to verify a yes answer to decision
problem input
o The inputs to verification algorithm are the original input and a
certificate
o Other problems like HAMILTONIAN CYCLE are known to have
polynomial bound algorithms but given a Hamiltonian cycle, It is easy to
verify that the cycle is indeed Hamiltonian in polynomial time.
o A verification algorithm , takes a problem instance x and verifies it, if
there exist a certificate y such that the answer for x with certificate y is
“yes”

6
A non-deterministic Algorithms

Nondeterministic algorithm = two stage procedure:


1) Non-deterministic (“guessing”) stage:
generate randomly an arbitrary string that can be
thought of as a candidate solution (“certificate”)

2) Deterministic (“verification”) stage:


take the certificate and the instance to the problem and
returns YES if the certificate represents a solution

NP algorithms (Nondeterministic polynomial)


verification stage is polynomial
7
P and NP

Summary:
• P solved in Polynomial time
• NP problem for which a solution can be verified in
polynomial time
• Unknown whether P=NP
• Hamiltonian-cycle problem is in NP
– Cannot solve in polynomial time
– Easy to verify solution in polynomial time

8
Is P = NP?
• Any problem in P is also in NP: P

P  NP NP

• The big (and open question) is whether NP  P


or P = NP
– i.e., if it is always easy to check a solution, should it
also be easy to find a solution?

• Most computer scientists believe that this is false


but we do not have a proof …
9
NP-Completeness
• By S. Cook and R Karp in 1970
P NP-complete
• It belief P ≠ NP so there is NP-Complete

• All problem in NP have same level of NP


difficulty

• NP-complete problems are defined as the hardest problems in NP


– If any one NP-Complete problem can be solved in polynomial time, Then every
NP-Complete problem can be solved in polynomial time

– If problem Q’  ex + f = 0 has solution

– Then problem Q (a x^2 + b x + c = 0) can be solved by transforming into Q’

– An instance of Q can be transformed.

• Most practical problems turn out to be either P or NP-complete.


10
Reductions
• Reduction is a way of saying that one problem is
“easier” than another.
• We say that problem A is easier than problem B,
(i.e., we write “A  B”)
if we can solve A using the algorithm that solves B.
• Idea: transform the inputs of A to inputs of B

yes
  yes
f Problem B no
no
Problem A
11
Polynomial Reductions

• Given two problems A, B, we say that A is

polynomially reducible to B (A p B) if:

1. There exists a function f that converts the input of A

to inputs of B in polynomial time

2. A(i) = YES  B(f(i)) = YES

12
NP-Completeness
• A problem B is NP-complete if:
P NP-complete
(1) B  NP
NP
(2) A p B for all A  NP

• If B satisfies only property (2) we say that B is NP-hard

• No polynomial time algorithm has been discovered for an


NP-Complete problem

• No one has ever proven that no polynomial time


algorithm can exist for any NP-Complete problem

13
Implications of Reduction

yes
  yes
f Problem B no
no
Problem A

- If A p B and B  P, then A  P
- if A p B and A  P, then B  P

14
Proving Polynomial Time

yes
  Polynomial time
yes
f
algorithm to decide B no
no

Polynomial time algorithm to decide A

1. Use a polynomial time reduction algorithm to


transform A into B
2. Run a known polynomial time algorithm for B
3. Use the answer for B as the answer for A

15
3SAT -Problem
Problem: Given Boolean formula of the form

( x1 x3 x6 ) ( x2 x3 x7)
Can you set the variables x1,x2,…..  { True, False}
Such that formula = T
------------------------
Guess : x1= True or False
(certification)
x2= True or False
x3= True or False
…………………………………….
Check formula : Return either True(Yes) or False(No) (verification)
{by using the value guessed}
o Goal of Verification algorithm is to verify a yes answer to decision problem input
16
o The inputs to verification algorithm are the original input and a certificate
17
18
19
20
21
22
23

You might also like