SlideShare uma empresa Scribd logo
1 de 40
Logistics
• HW due next week
• Midterm also next week on Tuesday
• But the HW is very essential for the midterm
• Do the HW! It is preparation for the exam
• Today’s lecture IS in the midterm
• Some part of Thursday’s lecture will be in the
midterm as well
• Thursday we will concentrate on ‘how can we
compute complexity’
P, NP, NP Hard, NP Complete
• Focus of this lecture = get the definitions
across
• This will be a part of midterm2
• Only some small part of the next lecture will
be part of the midterm
• Next lecture = some complexity examples
(non NP complete)
Complexity definitions (seen in 592)
• Big-Oh
• Big-Theta
• Big - Omega
Big Oh (O)
f(n)= O(g(n)) iff there exist positive constants c and n0 such that
f(n) ≤ cg(n) for all n ≥ n0
O-notation to give an upper bound on a function
Omega Notation
Big oh provides an asymptotic upper bound on a function.
Omega provides an asymptotic lower bound on a function.
Theta Notation
Theta notation is used when function f can be bounded both
from above and below by the same function g
How bad is exponential complexity
• Fibonacci example – the recursive fib cannot
even compute fib(50)
The class P
• The class P consists of those problems that are
solvable in polynomial time.
• More specifically, they are problems that can
be solved in time O(nk) for some constant k,
where n is the size of the input to the problem
• The key is that n is the size of input
What is the complexity of primality
testing?
public static boolean isPrime(int n){
boolean answer = (n>1)? true: false;
for(int i = 2; i*i <= n; ++i)
{
System.out.printf("%dn", i);
if(n%i == 0)
{
answer = false;
break;
}
}
return answer;
}
This loops until the square root of n
So this should be
But what is the input size?
How many bits does it take to
represent the number n?
log(n) = k
What is
Naïve primality testing is
exponential!!
Why obsess about primes?
• Crypto uses it heavily
• Primality testing actually is in P
• Proven in 2002
– Uses complicated number theory
– AKS primality test
NP
• NP is not the same as non-polynomial
complexity/running time. NP does not stand
for not polynomial.
• NP = Non-Deterministic polynomial time
• NP means verifiable in polynomial time
• Verifiable?
– If we are somehow given a ‘certificate’ of a
solution we can verify the legitimacy in
polynomial time
What happened to automata?
• Problem is in NP iff it is decidable by some non
deterministic Turing machine in polynomial time.
• Remember that the model we have used so far is a
deterministic Turing machine
• It is provable that a Non Deterministic Turing Machine is
equivalent to a Deterministic Turing Machine
• Remember NFA to DFA conversion?
– Given an NFA with n states how many states does the equivalent
DFA have?
– Worst case …. 2n
• The deterministic version of a poly time non deterministic
Turing machine will run in exponential time (worst case)
NP problems
• Graph theory has these fascinating(annoying?)
pairs of problems
– Shortest path algorithms?
– Longest path is NP complete (we’ll define NP
complete later)
– Eulerian tours (visit every vertex but cover every
edge only once, even degree etc). Solvable in
polynomial time!
– Hamiltonian tours (visit every vertex, no vertices
can be repeated). NP complete
Hamiltonian cycles
• Determining whether a directed graph has a
Hamiltonian cycle does not have a polynomial
time algorithm (yet!)
• However if someone was to give you a
sequence of vertices, determining whether or
not that sequence forms a Hamiltonian cycle
can be done in polynomial time
• Therefore Hamiltonian cycles are in NP
SAT
• A boolean formula is satisfiable if there exists
some assignment of the values 0 and 1 to its
variables that causes it to evaluate
to 1.
• CNF – Conjunctive Normal Form. ANDing of
clauses of ORs
2-CNF SAT
• Each or operation has two arguments that are
either variables or negation of variables
• The problem in 2 CNF SAT is to find
true/false(0 or 1) assignments to the variables
in order to make the entire formula true.
• Any of the OR clauses can be converted to
implication clauses
(xy)(yz)(xz)(zy)
2-SAT is in P
• Create the implication graph
x
y
x
z
z
y
Satisfiability via path finding
• If there is a path from
• And if there is a path from
• Then FAIL!
• How to find paths in graphs?
– DFS/BFS and modifications thereof
3 CNF SAT (3 SAT)
• Not so easy anymore.
• Implication graph cannot be constructed
• No known polytime algorithm
• Is it NP?
– If someone gives you a solution how long does it
take to verify it?
– Make one pass through the formula and check
• This is an NP problem
P is a subset of NP
• Since it takes polynomial time to run the
program, just run the program and get a
solution
• But is NP a subset of P?
• No one knows if P = NP or not
• Solve for a million dollars!
– http://www.claymath.org/millennium-problems
– The Poincare conjecture is solved today
What is not in NP?
• Undecidable problems
– Given a polynomial with integer coefficients, does it have
integer roots
– Hilbert’s nth problem
– Impossible to check for all the integers
– Even a non-deterministic TM has to have a finite number
of states!
– More on decidability later
• Tautology
– A boolean formula that is true for all possible assignments
– Here just one ‘verifier’ will not work. You have to try all
possible values
Amusing analogy
(thanks to lecture notes at University of Utah)
• Students believe that every problem assigned
to them is NP-complete in difficulty level, as
they have to find the solutions.
• Teaching Assistants, on the other hand, find
that their job is only as hard as NP, as they
only have to verify the student’s answers.
• When some students confound the TAs, even
verification becomes hard
Reducibility
• a problem Q can be reduced to another
problem Q’ if any instance of Q can be “easily
rephrased” as an instance of Q’, the solution
to which provides a solution to the instance of
Q
• Is a linear equation reducible to a quadratic
equation?
– Sure! Let coefficient of the square term be 0
NP - hard
• What are the hardest problems in NP?
• That notation means that L1 is reducible in
polynomial time to L2 .
• The less than symbol basically means that the
time taken to solve L1 is no worse that a
polynomial factor away from the time taken to
solve L2.
NP-hard
• A problem (a language) is said to NP-hard if
every problem in NP can be poly time reduced
to it.
NP Complete problems/languages
• Need to be in NP
• Need to be in NP-Hard
If both are satisfied then it is an NP complete problem
Reducibility is a transitive relation.
If we know a single problem in NP-Complete that helps when we are asked to
prove some other problem is NP-Complete
Assume problem P is NP Complete
All NP problems are reducible to this problem
Now given a different problem P’
If we show P reducible to P’
Then by transitivity all NP problems are reducible to P’
What is in NP-Complete
• For this course, we will axiomatically state that
the following problems are NP-Complete
• SAT – Given any boolean formula, is there
some assignment of values to the variables so
that the formula has a true value
• 3-CNF SAT
• Actually any boolean formula can be reduced
to 3-CNF form
An example reduction
• CLIQUE problem
• A clique in an undirected graph is a subset of
vertices such that each pair is connected by an
edge
• We want to take a problem instance in 3-CNF
SAT and convert it to CLIQUE finding
Reducing 3CNF SAT to CLIQUE
• Given – A boolean formula in 3 CNF SAT
• Goal – Produce a graph (in polynomial time) such
that
• We will construct a graph where satisfying
formula with k clauses is equivalent to finding a k
vertex clique.
CLIQUE
• An instance of a clique problem gives you 2
things as input
– Graph
– Some positive integer k
• Question being asked = do we have a clique
of size k in this graph
• Why can’t I just go through and pick all
possible k-subsets?
Decision problems versus optimization
problems
• Finding the maximum sized clique is an
optimization problem
• But we can reduce it to a series of decision
problems
– Can we find a clique of size 3 (why start at 3??)
– Can we find a clique of size 4
– Etc
• In general in our study of NP etc, we will focus
on decision problems
For each clause, create a vertex for each literal
For the edges
Connect vertices if they come from different clauses
Even if the vertices come from different clauses, do not connect if it
results in incompatibility. No variable should be connected to its not.
x1 x1 x1
┐x2 x2 x2
┐x3
x3 x3
┐
REDUCE 3-CNF SAT to CLIQUE
There are more
edges in here.
Refer to the
CLRS book to get
the complete
picture
Vertex cover problem
• A vertex cover of an undirected graph G=(V,E) is a
subset of vertices such that every edge is incident
to at least one of the vertices
• We’re typically interested in finding the minimum
sized vertex cover
• To show vertex cover is NP-complete
• What problem should we try to reduce to it
• It sounds like the ‘reverse’ of CLIQUE
• Reduction is done from CLIQUE to vertex cover
Clique of size k in G exists iff a vertex cover of size
|V| - k exists in G’ where G’ is the complement
graph (vertices that had an edge between then in G
do not have one in G’ and vice versa)
G
G’ =
Complement
Of
G
The original graph has a u,v,x,y CLIQUE. That is a clique of size 4
The complement graph has a vertex cover of size 6 (number of
vertices) – 4 (clique size). z,w is one such vertex cover.
The reducibility ‘tree’
• Richard Karp proved 21 problems to be NP
complete in a seminal 1971 paper
• Not that hard to read actually!
• Definitely not hard to read it to the point of
knowing what these problems are.
• karp's paper
Amusing/tragic NP story
• Breaking up over NP
Other NP complete problems
• Subset sum
• Given a set of positive integers and some
target t > 0,
do we have a subset that sums up to that
target set
• Why is the naïve algorithm going to be bad?
C←∅
while E = ∅
pick any {u, v} ∈ E
C ← C ∪ {u, v}
delete all edges incident to either u or v
return C
Approximation algorithm for Vertex cover
How bad is that approximation?
• Look at the edges returned in that algorithm
• Will the optimum vertex cover include at least one end
point of the edges returned from approx algorithm?

Mais conteúdo relacionado

Semelhante a PNP.pptx

Semelhante a PNP.pptx (20)

class23.ppt
class23.pptclass23.ppt
class23.ppt
 
UNIT-V.ppt
UNIT-V.pptUNIT-V.ppt
UNIT-V.ppt
 
Np completeness
Np completenessNp completeness
Np completeness
 
Np completeness h4
Np completeness  h4Np completeness  h4
Np completeness h4
 
P np &amp; np completeness
P np &amp; np completenessP np &amp; np completeness
P np &amp; np completeness
 
lecture 28
lecture 28lecture 28
lecture 28
 
Logic agent
Logic agentLogic agent
Logic agent
 
PropositionalLogic.ppt
PropositionalLogic.pptPropositionalLogic.ppt
PropositionalLogic.ppt
 
lecture 27
lecture 27lecture 27
lecture 27
 
DAA.pdf
DAA.pdfDAA.pdf
DAA.pdf
 
DAA.pdf
DAA.pdfDAA.pdf
DAA.pdf
 
Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10
 
Np completeness
Np completeness Np completeness
Np completeness
 
Ads unit 3 ppt
Ads unit 3 pptAds unit 3 ppt
Ads unit 3 ppt
 
m7-logic.ppt
m7-logic.pptm7-logic.ppt
m7-logic.ppt
 
CNIT 141: 9. Hard Problems
CNIT 141: 9. Hard ProblemsCNIT 141: 9. Hard Problems
CNIT 141: 9. Hard Problems
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
 
Algorithm_NP-Completeness Proof
Algorithm_NP-Completeness ProofAlgorithm_NP-Completeness Proof
Algorithm_NP-Completeness Proof
 
UNIT -IV DAA.pdf
UNIT  -IV DAA.pdfUNIT  -IV DAA.pdf
UNIT -IV DAA.pdf
 
CNIT 141 9. Hard Problems
CNIT 141 9. Hard ProblemsCNIT 141 9. Hard Problems
CNIT 141 9. Hard Problems
 

Último

Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
An introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxAn introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxPurva Nikam
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 

Último (20)

Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
An introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptxAn introduction to Semiconductor and its types.pptx
An introduction to Semiconductor and its types.pptx
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 

PNP.pptx

  • 1. Logistics • HW due next week • Midterm also next week on Tuesday • But the HW is very essential for the midterm • Do the HW! It is preparation for the exam • Today’s lecture IS in the midterm • Some part of Thursday’s lecture will be in the midterm as well • Thursday we will concentrate on ‘how can we compute complexity’
  • 2. P, NP, NP Hard, NP Complete • Focus of this lecture = get the definitions across • This will be a part of midterm2 • Only some small part of the next lecture will be part of the midterm • Next lecture = some complexity examples (non NP complete)
  • 3. Complexity definitions (seen in 592) • Big-Oh • Big-Theta • Big - Omega
  • 4. Big Oh (O) f(n)= O(g(n)) iff there exist positive constants c and n0 such that f(n) ≤ cg(n) for all n ≥ n0 O-notation to give an upper bound on a function
  • 5. Omega Notation Big oh provides an asymptotic upper bound on a function. Omega provides an asymptotic lower bound on a function.
  • 6. Theta Notation Theta notation is used when function f can be bounded both from above and below by the same function g
  • 7. How bad is exponential complexity • Fibonacci example – the recursive fib cannot even compute fib(50)
  • 8. The class P • The class P consists of those problems that are solvable in polynomial time. • More specifically, they are problems that can be solved in time O(nk) for some constant k, where n is the size of the input to the problem • The key is that n is the size of input
  • 9. What is the complexity of primality testing? public static boolean isPrime(int n){ boolean answer = (n>1)? true: false; for(int i = 2; i*i <= n; ++i) { System.out.printf("%dn", i); if(n%i == 0) { answer = false; break; } } return answer; } This loops until the square root of n So this should be But what is the input size? How many bits does it take to represent the number n? log(n) = k What is Naïve primality testing is exponential!!
  • 10. Why obsess about primes? • Crypto uses it heavily • Primality testing actually is in P • Proven in 2002 – Uses complicated number theory – AKS primality test
  • 11. NP • NP is not the same as non-polynomial complexity/running time. NP does not stand for not polynomial. • NP = Non-Deterministic polynomial time • NP means verifiable in polynomial time • Verifiable? – If we are somehow given a ‘certificate’ of a solution we can verify the legitimacy in polynomial time
  • 12. What happened to automata? • Problem is in NP iff it is decidable by some non deterministic Turing machine in polynomial time. • Remember that the model we have used so far is a deterministic Turing machine • It is provable that a Non Deterministic Turing Machine is equivalent to a Deterministic Turing Machine • Remember NFA to DFA conversion? – Given an NFA with n states how many states does the equivalent DFA have? – Worst case …. 2n • The deterministic version of a poly time non deterministic Turing machine will run in exponential time (worst case)
  • 13. NP problems • Graph theory has these fascinating(annoying?) pairs of problems – Shortest path algorithms? – Longest path is NP complete (we’ll define NP complete later) – Eulerian tours (visit every vertex but cover every edge only once, even degree etc). Solvable in polynomial time! – Hamiltonian tours (visit every vertex, no vertices can be repeated). NP complete
  • 14. Hamiltonian cycles • Determining whether a directed graph has a Hamiltonian cycle does not have a polynomial time algorithm (yet!) • However if someone was to give you a sequence of vertices, determining whether or not that sequence forms a Hamiltonian cycle can be done in polynomial time • Therefore Hamiltonian cycles are in NP
  • 15. SAT • A boolean formula is satisfiable if there exists some assignment of the values 0 and 1 to its variables that causes it to evaluate to 1. • CNF – Conjunctive Normal Form. ANDing of clauses of ORs
  • 16. 2-CNF SAT • Each or operation has two arguments that are either variables or negation of variables • The problem in 2 CNF SAT is to find true/false(0 or 1) assignments to the variables in order to make the entire formula true. • Any of the OR clauses can be converted to implication clauses (xy)(yz)(xz)(zy)
  • 17. 2-SAT is in P • Create the implication graph x y x z z y
  • 18. Satisfiability via path finding • If there is a path from • And if there is a path from • Then FAIL! • How to find paths in graphs? – DFS/BFS and modifications thereof
  • 19. 3 CNF SAT (3 SAT) • Not so easy anymore. • Implication graph cannot be constructed • No known polytime algorithm • Is it NP? – If someone gives you a solution how long does it take to verify it? – Make one pass through the formula and check • This is an NP problem
  • 20. P is a subset of NP • Since it takes polynomial time to run the program, just run the program and get a solution • But is NP a subset of P? • No one knows if P = NP or not • Solve for a million dollars! – http://www.claymath.org/millennium-problems – The Poincare conjecture is solved today
  • 21. What is not in NP? • Undecidable problems – Given a polynomial with integer coefficients, does it have integer roots – Hilbert’s nth problem – Impossible to check for all the integers – Even a non-deterministic TM has to have a finite number of states! – More on decidability later • Tautology – A boolean formula that is true for all possible assignments – Here just one ‘verifier’ will not work. You have to try all possible values
  • 22. Amusing analogy (thanks to lecture notes at University of Utah) • Students believe that every problem assigned to them is NP-complete in difficulty level, as they have to find the solutions. • Teaching Assistants, on the other hand, find that their job is only as hard as NP, as they only have to verify the student’s answers. • When some students confound the TAs, even verification becomes hard
  • 23. Reducibility • a problem Q can be reduced to another problem Q’ if any instance of Q can be “easily rephrased” as an instance of Q’, the solution to which provides a solution to the instance of Q • Is a linear equation reducible to a quadratic equation? – Sure! Let coefficient of the square term be 0
  • 24. NP - hard • What are the hardest problems in NP? • That notation means that L1 is reducible in polynomial time to L2 . • The less than symbol basically means that the time taken to solve L1 is no worse that a polynomial factor away from the time taken to solve L2.
  • 25. NP-hard • A problem (a language) is said to NP-hard if every problem in NP can be poly time reduced to it.
  • 26. NP Complete problems/languages • Need to be in NP • Need to be in NP-Hard If both are satisfied then it is an NP complete problem Reducibility is a transitive relation. If we know a single problem in NP-Complete that helps when we are asked to prove some other problem is NP-Complete Assume problem P is NP Complete All NP problems are reducible to this problem Now given a different problem P’ If we show P reducible to P’ Then by transitivity all NP problems are reducible to P’
  • 27. What is in NP-Complete • For this course, we will axiomatically state that the following problems are NP-Complete • SAT – Given any boolean formula, is there some assignment of values to the variables so that the formula has a true value • 3-CNF SAT • Actually any boolean formula can be reduced to 3-CNF form
  • 28. An example reduction • CLIQUE problem • A clique in an undirected graph is a subset of vertices such that each pair is connected by an edge • We want to take a problem instance in 3-CNF SAT and convert it to CLIQUE finding
  • 29. Reducing 3CNF SAT to CLIQUE • Given – A boolean formula in 3 CNF SAT • Goal – Produce a graph (in polynomial time) such that • We will construct a graph where satisfying formula with k clauses is equivalent to finding a k vertex clique.
  • 30. CLIQUE • An instance of a clique problem gives you 2 things as input – Graph – Some positive integer k • Question being asked = do we have a clique of size k in this graph • Why can’t I just go through and pick all possible k-subsets?
  • 31. Decision problems versus optimization problems • Finding the maximum sized clique is an optimization problem • But we can reduce it to a series of decision problems – Can we find a clique of size 3 (why start at 3??) – Can we find a clique of size 4 – Etc • In general in our study of NP etc, we will focus on decision problems
  • 32. For each clause, create a vertex for each literal For the edges Connect vertices if they come from different clauses Even if the vertices come from different clauses, do not connect if it results in incompatibility. No variable should be connected to its not. x1 x1 x1 ┐x2 x2 x2 ┐x3 x3 x3 ┐ REDUCE 3-CNF SAT to CLIQUE There are more edges in here. Refer to the CLRS book to get the complete picture
  • 33. Vertex cover problem • A vertex cover of an undirected graph G=(V,E) is a subset of vertices such that every edge is incident to at least one of the vertices • We’re typically interested in finding the minimum sized vertex cover • To show vertex cover is NP-complete • What problem should we try to reduce to it • It sounds like the ‘reverse’ of CLIQUE • Reduction is done from CLIQUE to vertex cover
  • 34. Clique of size k in G exists iff a vertex cover of size |V| - k exists in G’ where G’ is the complement graph (vertices that had an edge between then in G do not have one in G’ and vice versa) G G’ = Complement Of G
  • 35. The original graph has a u,v,x,y CLIQUE. That is a clique of size 4 The complement graph has a vertex cover of size 6 (number of vertices) – 4 (clique size). z,w is one such vertex cover.
  • 36. The reducibility ‘tree’ • Richard Karp proved 21 problems to be NP complete in a seminal 1971 paper • Not that hard to read actually! • Definitely not hard to read it to the point of knowing what these problems are. • karp's paper
  • 37. Amusing/tragic NP story • Breaking up over NP
  • 38. Other NP complete problems • Subset sum • Given a set of positive integers and some target t > 0, do we have a subset that sums up to that target set • Why is the naïve algorithm going to be bad?
  • 39. C←∅ while E = ∅ pick any {u, v} ∈ E C ← C ∪ {u, v} delete all edges incident to either u or v return C Approximation algorithm for Vertex cover
  • 40. How bad is that approximation? • Look at the edges returned in that algorithm • Will the optimum vertex cover include at least one end point of the edges returned from approx algorithm?