NP Complete Notes
NP Complete Notes
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
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
yes
yes
f Problem B no
no
Problem A
11
Polynomial Reductions
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
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
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