SlideShare una empresa de Scribd logo
1 de 36
Design and
Analysis of
Algorithms
NP-COMPLETENESS
 Instructor
Prof. Amrinder Arora
amrinder@gwu.edu
Please copy TA on emails
Please feel free to call as well

 Available for study sessions
Science and Engineering Hall
GWU
Algorithms NP-Completeness 2
LOGISTICS
Algorithms
Analysis
Asymptotic
NP-
Completeness
Design
D&C
Greedy
DP
Graph
B&B
Applications
Algorithms NP-Completeness 3
WHERE WE ARE
 Done
 Done
 Done
 Done
 Done
 Done
 Starting now..
Now that we
have
finished
studying
algorithmic
techniques,
we are..
Algorithms 4NP-Completeness
ON TO ANALYZING
CLASSES OF PROBLEMS
“Any question can be made
immaterial by subsuming all its
answers under a common head.
The sovereign road to
indifference, whether to evils or
to goods, lies in the thought of
the higher genus.”
Algorithms NP-Completeness 5
THE HIGHER GENUS
William James
 https://www.youtube.com/watch?v=YX40hbAHx3s
Algorithms NP-Completeness 6
FIRST, A VIDEO
 P = { L | L is accepted by a deterministic Turing
Machine in polynomial time}
 The TM takes at most O(nc) steps to accept a string of length n
 NP = { L | L is accepted by a non-deterministic Turing
Machine in polynomial time }
 The TM takes at most O(nc) steps on each computation path to
accept a string of length n
 They are sets of languages
Algorithms NP-Completeness 7
THE CLASS P AND THE CLASS NP
 A language is defined as a set of strings
 For example, if an alphabet is {a, b, c}, then a language can be:
{“a”, “ab”, “ac”}. Another language can be: {“ab”, “abab”,
“ababab”, “abababab”, “ababababab”, …}. Languages can be
finite or infinite.
 Problem is typically defined as when we are asked to
find/solve, or at least confirm something.
 For example, given a graph G does it have a Hamiltonian Cycle?
Algorithms NP-Completeness 8
LANGUAGES VS. PROBLEMS
 A problem instance can also be encoded as a String.
For example, a graph G can be encoded where the
first line of the input file contains the number of
nodes n, then the edges, etc.
 If the algorithm (Turing Machine) accepts that input,
that input is in the language of the Turing Machine.
 All inputs that are valid graphs and have Hamiltonian
Cycles, can be accepted. All inputs that are either
malformed (not a graph) or don’t have Hamiltonian
cycle, can be rejected.
Algorithms NP-Completeness 9
ENCODING A PROBLEM
 Thus, a language L is a mathematical way of
representing what we usually define as a problem.
Algorithms NP-Completeness 10
LANGUAGES ARE PROBLEMS
 P = { L | L is accepted by a deterministic Turing
Machine in polynomial time}
 The TM takes at most O(nc) steps to accept a string of length n
 NP = { L | L is accepted by a non-deterministic Turing
Machine in polynomial time }
 The TM takes at most O(nc) steps on each computation path to
accept a string of length n
 They are sets of languages
 Or, as we now know, P and NP are classes (sets) of
problems.
Algorithms NP-Completeness 11
THE CLASS P AND THE CLASS NP
Algorithms NP-Completeness 12
TURING MACHINE REFRESHER
. . .
Infinite tape: Γ*
Tape head: read current square on tape,
write into current square,
move one square left or right
FSM: like PDA, except:
transitions also include direction (left/right)
final accepting and rejecting states
FSM
 Are non-deterministic Turing machines really more
powerful (efficient) than deterministic ones?
 Essence of P vs. NP problem
 Does non-determinism help?
 In case of automata – there is no difference
 In case of PDA – yes, there is a difference
 In case of TM, we do not know
Algorithms NP-Completeness 13
D TM VS. N TM
 One of the most important unanswered questions since
1960s
 Many optimization problems appear amenable only to brute force,
i.e. (near-)exhaustive enumeration.
 Edmonds 1966: “The classes of problems which are respectively
known and not known to have good algorithms are of great
theoretical interest […] I conjecture that there is no good
algorithm for the traveling salesman problem. My reasons are the
same as for any mathematical conjecture: (1) It’s a legitimate
mathematical possibility, and (2) I do not know.”
 How can we make progress on this problem?
 We could find an algorithm for every NP problem
 We could use polynomial time reductions to find the “hardest”
problems and just work on those
Algorithms NP-Completeness 14
P = NP?
Input for
Problem B
Output for
Problem B
Algorithm for Problem B
Reduction
from
B to A
Algorithm
for A
x R(x)
Yes/No
Algorithms NP-Completeness 15
REDUCIBILITY
 How would you define NP-Complete?
 They are the “hardest” problems in NP
Algorithms NP-Completeness 16
NP-COMPLETENESS
P
NP
NP-Complete
Q is an NP-Complete problem if:
1) Q is in NP
2) Every other NP problem polynomial time reducible
to Q
Algorithms NP-Completeness 17
DEFINITION OF NP-COMPLETE
Algorithms NP-Completeness 18
 Satisfiability problem: Given a boolean formula, find whether it
has a satisfying assignment or not.
 For example, say the formula is:
(x1 or x2 or x3) and (x1 or n(x2) or n(x3)) and
(n(x1) or x2 or n(x3)) and (n(x1) or n(x2) or n(x3)) and
(n(x1) or x2 or x3) and (x1 or n(x2) or x3) and
(x1 or n(x2) or n(x3)) and (n(x1) or x2 or n(x3))
 Here n(x1) represents the negation of x1. So, if x1 is true, then
n(x1) is false, and vice versa.
 So, if we assign x1 = x2 = x3 = true, then overall clause
becomes:
(T or T or T) and (T or F or F) and (F or T or F) and (F or F or F)
and
(F or T or T) and (T or F or T) and (T or F or F) and (F or T or F),
which becomes: T and T and T and F and T and T and T and T = F
= false.
 So, this assignment does not satisfy this clause.
 Some other true/false assignment to variables may satisfy this
clause, or it is possible that this clause is not satisfiable.
SAT
Save your job
Well, I can’t solve it, but so can’t thousands of
other computer scientists working for past 40
years on this problem X (even if we just invented
X)
Approximation
Chances of coming with an optimal solution to X
are slim, perhaps we can focus on approximate
solution instead?
Computability
X may really be impossible to solve in
polynomial time, and perhaps we need to
simplify it to solve it in reasonable amount of
time.
Algorithms NP-Completeness 19
TOP 3 REASONS TO PROVE PROBLEM X IS
NP-COMPLETE
Input for
Problem B
Output for
Problem B
Reduction
from
B to A
Algorithm
for A
x R(x) Yes/No
 Algorithm for Problem B
Algorithms NP-Completeness 20
REDUCIBILITY
Problem A is at least as hard as Problem B.
 Satisfiability problem is that given a boolean formula, we have to
find whether it has a satisfying assignment or not.
 For example, say the formula is:
(x1 or x2 or x3)
and (x1 or n(x2) or n(x3))
and (n(x1) or x2 or n(x3))
and (n(x1) or n(x2) or n(x3))
and (n(x1) or x2 or x3)
and (x1 or n(x2) or x3)
and (x1 or n(x2) or n(x3))
and (n(x1) or x2 or n(x3))
 Here n(x1) represents the negation of x1. So, if x1 is true, then
n(x1) is false, and vice versa.
Algorithms NP-Completeness 21
SAT
22
Suppose we are given a NTM N and a string w of length
n which is decided by N in f(n) or fewer
nondeterministic steps.
Then there is an explicit CNF formula f of length O
(f(n)3) which is satisfiable iff N accepts w.
In particular, when f(n) is a polynomial, f has
polynomial length in terms of n so that every language
in NP reduces to CSAT in polynomial time. Thus CSAT
is NP-hard.
Finally, as CSAT is in NP, CSAT is NP-complete.
Algorithms NP-Completeness
COOK - LEVIN
THEOREM
To show that X is NP-Complete:
1. Show that X is in NP, i.e., a polynomial time verifier
exists for X.
2. Pick a suitable known NP-complete problem, S (ex:
SAT)
3. Show a polynomial algorithm to transform an
instance of S into an instance of X
SOX RESTOX mnemonic can help.
SAT Outside the Box
Reduce SAT To X
Algorithms NP-Completeness 23
NP-COMPLETENESS PROOF METHOD
To show that X is NP-Complete:
1. Show that X is in NP, i.e., a polynomial time verifier
exists for X.
2. Pick a suitable known NP-complete problem, S (ex:
SAT)
3. Show a polynomial algorithm to transform an
instance of S into an instance of X
a) Draw the boxes, including inputs and outputs
b) Write relationship between the inputs
c) Describe the transformation
Algorithms NP-Completeness 24
NP-COMPLETENESS PROOF METHOD (CONT.)
Input for
Problem B
Output for
Problem B
Reduction
from
B to A
Algorithm
for A
x R(x) Yes/No
 Algorithm for Problem B
Algorithms NP-Completeness 25
REDUCIBILITY
Problem A is at least as hard as Problem B.
 CLIQUE = { <G,k> | G is a graph with a clique of size
k }
 A clique is a subset of vertices that are all connected
 Why is CLIQUE in NP?
Algorithms NP-Completeness 26
EXAMPLE: CLIQUE
Textbook Section 9.5.1
 Pick an instance of 3-SAT, Φ, with k clauses
 Make a vertex for each literal
 Connect each vertex to the literals in other clauses
that are not the negation
 Any k-clique in this graph corresponds to a satisfying
assignment
Algorithms NP-Completeness 27
REDUCING 3-SAT TO CLIQUE
Algorithms NP-Completeness 28
REDUCING 3-SAT TO CLIQUE (CONT.)
 INDEPENDENT SET = { <G,k> | where G has an
independent set of size k }
 An independent set is a set of vertices, such that
there are no edge between any two vertices in that
set (two people are “independent” if they do not
know each other).
 How can we reduce the clique problem to IS?
Algorithms NP-Completeness 29
EXAMPLE: INDEPENDENT SET (IS)
 This is the dual problem!
 Complement of a graph: Same vertices, but
“reversed” edges – remove the ones that exist, and
add the ones that don’t.
Algorithms NP-Completeness 30
CLIQUE TO INDEPENDENT SET
HAMILTONIAN PATH TO HAMILTONIAN CYCLE
Algorithms NP-Completeness 31
 Given a graph G = (V,E), construct a graph G’ =
(V’,E’), such that:
 V’ = V union {z}
 E’ = E union {(z,v) | all v in V}
 G’ has one more vertex, and n more edges
 Claim:
 G has a Hamiltonian Path if and only if G’ has a Hamiltonian
Cycle
HAMILTONIAN CYCLE TO HAMILTONIAN PATH
Algorithms NP-Completeness 32
 Given a graph G = (V,E), construct a graph G’ =
(V’,E’), such that:
 V’ = V union {z, w, x}
 E’ = E union new edges.
 Firstly, select a random edge {u,v} in E.
 {w,u}
 {x,v} for all v connected to u.
 {z,x}
[Thus, G’ has 3 more vertices, and a few more edges]
 Claim:
 G has a Hamiltonian Cycle if and only if G’ has a Hamiltonian
Path
 Algorithm for Independent Set
Algorithms NP-Completeness 33
INDEPENDENT SET TO VERTEX COVER
Input for
Independent
Set
Output for
Independent
Set
Transformation
G’ = G
Algorithm for
Vertex Cover
G,k G’,n-k Yes/No
 Show the following polynomial time reductions
 Independent Set P Vertex Cover
 Vertex Cover P Dominating Set
 3-SAT P Vertex Cover
 Hamiltonian Cycle P Hamiltonian Path
Algorithms NP-Completeness 34
PRACTICE NP-COMPLETENESS REDUCTIONS
 NP complete problems are the HARDEST problems in
NP
 Reducibility – Art of reducing one problem to another
 Any problem in NP can be reduced to any NP-
complete problem in polynomial time.
 Is P = NP? This is one of the most fascinating
question in Computer Science today, with
phenomenal impacts if proven in affirmative.
 Reducing problems can be hard, takes practice
 SAT and 3-SAT are one of the earlier known NP-
complete problems, today there are thousands.
Algorithms NP-Completeness 35
SUMMARY
 To prove a problem X is NP-complete, remember to
do two things:
 Show X is in NP
 Take a well known NP-complete problem, such as SAT, and
reduce SAT to X.
 SOX RESTOX mnemonic may help
Algorithms NP-Completeness 36
SUMMARY

Más contenido relacionado

La actualidad más candente

The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen ProblemSukrit Gupta
 
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Shuvongkor Barman
 
Introduction to Approximation Algorithms
Introduction to Approximation AlgorithmsIntroduction to Approximation Algorithms
Introduction to Approximation AlgorithmsJhoirene Clemente
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using BacktrackingAbhishek Singh
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}FellowBuddy.com
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardAnimesh Chaturvedi
 
Bellman Ford's Algorithm
Bellman Ford's AlgorithmBellman Ford's Algorithm
Bellman Ford's AlgorithmTanmay Baranwal
 
Artificial Intelligence -- Search Algorithms
Artificial Intelligence-- Search Algorithms Artificial Intelligence-- Search Algorithms
Artificial Intelligence -- Search Algorithms Syed Ahmed
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
Lecture optimal binary search tree
Lecture optimal binary search tree Lecture optimal binary search tree
Lecture optimal binary search tree Divya Ks
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back trackingTech_MX
 

La actualidad más candente (20)

The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
Daa notes 3
Daa notes 3Daa notes 3
Daa notes 3
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
Backtracking
Backtracking  Backtracking
Backtracking
 
Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)Presentation on Breadth First Search (BFS)
Presentation on Breadth First Search (BFS)
 
Introduction to Approximation Algorithms
Introduction to Approximation AlgorithmsIntroduction to Approximation Algorithms
Introduction to Approximation Algorithms
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
 
Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}Heuristic Search Techniques {Artificial Intelligence}
Heuristic Search Techniques {Artificial Intelligence}
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
Bellman Ford's Algorithm
Bellman Ford's AlgorithmBellman Ford's Algorithm
Bellman Ford's Algorithm
 
N queens using backtracking
N queens using backtrackingN queens using backtracking
N queens using backtracking
 
Approximation Algorithms
Approximation AlgorithmsApproximation Algorithms
Approximation Algorithms
 
First order logic
First order logicFirst order logic
First order logic
 
AI: AI & Problem Solving
AI: AI & Problem SolvingAI: AI & Problem Solving
AI: AI & Problem Solving
 
Artificial Intelligence -- Search Algorithms
Artificial Intelligence-- Search Algorithms Artificial Intelligence-- Search Algorithms
Artificial Intelligence -- Search Algorithms
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Lecture optimal binary search tree
Lecture optimal binary search tree Lecture optimal binary search tree
Lecture optimal binary search tree
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 

Destacado (8)

lecture 28
lecture 28lecture 28
lecture 28
 
Lexical
LexicalLexical
Lexical
 
P vs NP
P vs NPP vs NP
P vs NP
 
Las clases P NP y NP completo
Las clases P NP y NP completoLas clases P NP y NP completo
Las clases P NP y NP completo
 
np complete
np completenp complete
np complete
 
P vs NP
P vs NPP vs NP
P vs NP
 
P versus NP
P versus NPP versus NP
P versus NP
 
The Top Skills That Can Get You Hired in 2017
The Top Skills That Can Get You Hired in 2017The Top Skills That Can Get You Hired in 2017
The Top Skills That Can Get You Hired in 2017
 

Similar a NP completeness

UNIT-V.pdf daa unit material 5 th unit ppt
UNIT-V.pdf daa unit material 5 th unit pptUNIT-V.pdf daa unit material 5 th unit ppt
UNIT-V.pdf daa unit material 5 th unit pptJyoReddy9
 
Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10chidabdu
 
2009 CSBB LAB 新生訓練
2009 CSBB LAB 新生訓練2009 CSBB LAB 新生訓練
2009 CSBB LAB 新生訓練Abner Huang
 
Np completeness h4
Np completeness  h4Np completeness  h4
Np completeness h4Rajendran
 
P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2S.Shayan Daneshvar
 
2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiouvafopoulos
 
P-NP-and-the-Polynomial-Space.ppt
P-NP-and-the-Polynomial-Space.pptP-NP-and-the-Polynomial-Space.ppt
P-NP-and-the-Polynomial-Space.pptHetansheeShah2
 
Introduction to complexity theory assignment
Introduction to complexity theory assignmentIntroduction to complexity theory assignment
Introduction to complexity theory assignmenttesfahunegn minwuyelet
 
Limits of Computation
Limits of ComputationLimits of Computation
Limits of ComputationJoshua Reuben
 
The Limits of Computation
The Limits of ComputationThe Limits of Computation
The Limits of ComputationJoshua Reuben
 

Similar a NP completeness (20)

UNIT-V.pdf daa unit material 5 th unit ppt
UNIT-V.pdf daa unit material 5 th unit pptUNIT-V.pdf daa unit material 5 th unit ppt
UNIT-V.pdf daa unit material 5 th unit ppt
 
NP-Completeness - II
NP-Completeness - IINP-Completeness - II
NP-Completeness - II
 
class23.ppt
class23.pptclass23.ppt
class23.ppt
 
Internship
InternshipInternship
Internship
 
NP Complete Problems in Graph Theory
NP Complete Problems in Graph TheoryNP Complete Problems in Graph Theory
NP Complete Problems in Graph Theory
 
Teori pnp
Teori pnpTeori pnp
Teori pnp
 
Algorithm chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10
 
2009 CSBB LAB 新生訓練
2009 CSBB LAB 新生訓練2009 CSBB LAB 新生訓練
2009 CSBB LAB 新生訓練
 
Np completeness h4
Np completeness  h4Np completeness  h4
Np completeness h4
 
Introduction
IntroductionIntroduction
Introduction
 
P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2P, NP and NP-Complete, Theory of NP-Completeness V2
P, NP and NP-Complete, Theory of NP-Completeness V2
 
CSE680-17NP-Complete.pptx
CSE680-17NP-Complete.pptxCSE680-17NP-Complete.pptx
CSE680-17NP-Complete.pptx
 
AA ppt9107
AA ppt9107AA ppt9107
AA ppt9107
 
2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou
 
P-NP-and-the-Polynomial-Space.ppt
P-NP-and-the-Polynomial-Space.pptP-NP-and-the-Polynomial-Space.ppt
P-NP-and-the-Polynomial-Space.ppt
 
P vs NP
P vs NP P vs NP
P vs NP
 
Introduction to complexity theory assignment
Introduction to complexity theory assignmentIntroduction to complexity theory assignment
Introduction to complexity theory assignment
 
Turing machine
Turing machineTuring machine
Turing machine
 
Limits of Computation
Limits of ComputationLimits of Computation
Limits of Computation
 
The Limits of Computation
The Limits of ComputationThe Limits of Computation
The Limits of Computation
 

Más de Amrinder Arora

Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Amrinder Arora
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchAmrinder Arora
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalAmrinder Arora
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Amrinder Arora
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaAmrinder Arora
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Amrinder Arora
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Amrinder Arora
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Amrinder Arora
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine LearningAmrinder Arora
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisAmrinder Arora
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part IIAmrinder Arora
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1Amrinder Arora
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsAmrinder Arora
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1Amrinder Arora
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAmrinder Arora
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationAmrinder Arora
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersAmrinder Arora
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsAmrinder Arora
 

Más de Amrinder Arora (20)

Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
Convex Hull - Chan's Algorithm O(n log h) - Presentation by Yitian Huang and ...
 
Graph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First SearchGraph Traversal Algorithms - Breadth First Search
Graph Traversal Algorithms - Breadth First Search
 
Graph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search TraversalGraph Traversal Algorithms - Depth First Search Traversal
Graph Traversal Algorithms - Depth First Search Traversal
 
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
Bron Kerbosch Algorithm - Presentation by Jun Zhai, Tianhang Qiang and Yizhen...
 
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet MahanaArima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
Arima Forecasting - Presentation by Sera Cresta, Nora Alosaimi and Puneet Mahana
 
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
Stopping Rule for Secretory Problem - Presentation by Haoyang Tian, Wesam Als...
 
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
Proof of O(log *n) time complexity of Union find (Presentation by Wei Li, Zeh...
 
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
Proof of Cook Levin Theorem (Presentation by Xiechuan, Song and Shuo)
 
Online algorithms in Machine Learning
Online algorithms in Machine LearningOnline algorithms in Machine Learning
Online algorithms in Machine Learning
 
Algorithmic Puzzles
Algorithmic PuzzlesAlgorithmic Puzzles
Algorithmic Puzzles
 
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity AnalysisEuclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
Euclid's Algorithm for Greatest Common Divisor - Time Complexity Analysis
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
 
Dynamic Programming - Part 1
Dynamic Programming - Part 1Dynamic Programming - Part 1
Dynamic Programming - Part 1
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
Set Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom FiltersSet Operations - Union Find and Bloom Filters
Set Operations - Union Find and Bloom Filters
 
Binomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci HeapsBinomial Heaps and Fibonacci Heaps
Binomial Heaps and Fibonacci Heaps
 

Último

9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesDavid Newbury
 

Último (20)

9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
201610817 - edge part1
201610817 - edge part1201610817 - edge part1
201610817 - edge part1
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
Linked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond OntologiesLinked Data in Production: Moving Beyond Ontologies
Linked Data in Production: Moving Beyond Ontologies
 

NP completeness

  • 2.  Instructor Prof. Amrinder Arora amrinder@gwu.edu Please copy TA on emails Please feel free to call as well   Available for study sessions Science and Engineering Hall GWU Algorithms NP-Completeness 2 LOGISTICS
  • 4. Now that we have finished studying algorithmic techniques, we are.. Algorithms 4NP-Completeness ON TO ANALYZING CLASSES OF PROBLEMS
  • 5. “Any question can be made immaterial by subsuming all its answers under a common head. The sovereign road to indifference, whether to evils or to goods, lies in the thought of the higher genus.” Algorithms NP-Completeness 5 THE HIGHER GENUS William James
  • 7.  P = { L | L is accepted by a deterministic Turing Machine in polynomial time}  The TM takes at most O(nc) steps to accept a string of length n  NP = { L | L is accepted by a non-deterministic Turing Machine in polynomial time }  The TM takes at most O(nc) steps on each computation path to accept a string of length n  They are sets of languages Algorithms NP-Completeness 7 THE CLASS P AND THE CLASS NP
  • 8.  A language is defined as a set of strings  For example, if an alphabet is {a, b, c}, then a language can be: {“a”, “ab”, “ac”}. Another language can be: {“ab”, “abab”, “ababab”, “abababab”, “ababababab”, …}. Languages can be finite or infinite.  Problem is typically defined as when we are asked to find/solve, or at least confirm something.  For example, given a graph G does it have a Hamiltonian Cycle? Algorithms NP-Completeness 8 LANGUAGES VS. PROBLEMS
  • 9.  A problem instance can also be encoded as a String. For example, a graph G can be encoded where the first line of the input file contains the number of nodes n, then the edges, etc.  If the algorithm (Turing Machine) accepts that input, that input is in the language of the Turing Machine.  All inputs that are valid graphs and have Hamiltonian Cycles, can be accepted. All inputs that are either malformed (not a graph) or don’t have Hamiltonian cycle, can be rejected. Algorithms NP-Completeness 9 ENCODING A PROBLEM
  • 10.  Thus, a language L is a mathematical way of representing what we usually define as a problem. Algorithms NP-Completeness 10 LANGUAGES ARE PROBLEMS
  • 11.  P = { L | L is accepted by a deterministic Turing Machine in polynomial time}  The TM takes at most O(nc) steps to accept a string of length n  NP = { L | L is accepted by a non-deterministic Turing Machine in polynomial time }  The TM takes at most O(nc) steps on each computation path to accept a string of length n  They are sets of languages  Or, as we now know, P and NP are classes (sets) of problems. Algorithms NP-Completeness 11 THE CLASS P AND THE CLASS NP
  • 12. Algorithms NP-Completeness 12 TURING MACHINE REFRESHER . . . Infinite tape: Γ* Tape head: read current square on tape, write into current square, move one square left or right FSM: like PDA, except: transitions also include direction (left/right) final accepting and rejecting states FSM
  • 13.  Are non-deterministic Turing machines really more powerful (efficient) than deterministic ones?  Essence of P vs. NP problem  Does non-determinism help?  In case of automata – there is no difference  In case of PDA – yes, there is a difference  In case of TM, we do not know Algorithms NP-Completeness 13 D TM VS. N TM
  • 14.  One of the most important unanswered questions since 1960s  Many optimization problems appear amenable only to brute force, i.e. (near-)exhaustive enumeration.  Edmonds 1966: “The classes of problems which are respectively known and not known to have good algorithms are of great theoretical interest […] I conjecture that there is no good algorithm for the traveling salesman problem. My reasons are the same as for any mathematical conjecture: (1) It’s a legitimate mathematical possibility, and (2) I do not know.”  How can we make progress on this problem?  We could find an algorithm for every NP problem  We could use polynomial time reductions to find the “hardest” problems and just work on those Algorithms NP-Completeness 14 P = NP?
  • 15. Input for Problem B Output for Problem B Algorithm for Problem B Reduction from B to A Algorithm for A x R(x) Yes/No Algorithms NP-Completeness 15 REDUCIBILITY
  • 16.  How would you define NP-Complete?  They are the “hardest” problems in NP Algorithms NP-Completeness 16 NP-COMPLETENESS P NP NP-Complete
  • 17. Q is an NP-Complete problem if: 1) Q is in NP 2) Every other NP problem polynomial time reducible to Q Algorithms NP-Completeness 17 DEFINITION OF NP-COMPLETE
  • 18. Algorithms NP-Completeness 18  Satisfiability problem: Given a boolean formula, find whether it has a satisfying assignment or not.  For example, say the formula is: (x1 or x2 or x3) and (x1 or n(x2) or n(x3)) and (n(x1) or x2 or n(x3)) and (n(x1) or n(x2) or n(x3)) and (n(x1) or x2 or x3) and (x1 or n(x2) or x3) and (x1 or n(x2) or n(x3)) and (n(x1) or x2 or n(x3))  Here n(x1) represents the negation of x1. So, if x1 is true, then n(x1) is false, and vice versa.  So, if we assign x1 = x2 = x3 = true, then overall clause becomes: (T or T or T) and (T or F or F) and (F or T or F) and (F or F or F) and (F or T or T) and (T or F or T) and (T or F or F) and (F or T or F), which becomes: T and T and T and F and T and T and T and T = F = false.  So, this assignment does not satisfy this clause.  Some other true/false assignment to variables may satisfy this clause, or it is possible that this clause is not satisfiable. SAT
  • 19. Save your job Well, I can’t solve it, but so can’t thousands of other computer scientists working for past 40 years on this problem X (even if we just invented X) Approximation Chances of coming with an optimal solution to X are slim, perhaps we can focus on approximate solution instead? Computability X may really be impossible to solve in polynomial time, and perhaps we need to simplify it to solve it in reasonable amount of time. Algorithms NP-Completeness 19 TOP 3 REASONS TO PROVE PROBLEM X IS NP-COMPLETE
  • 20. Input for Problem B Output for Problem B Reduction from B to A Algorithm for A x R(x) Yes/No  Algorithm for Problem B Algorithms NP-Completeness 20 REDUCIBILITY Problem A is at least as hard as Problem B.
  • 21.  Satisfiability problem is that given a boolean formula, we have to find whether it has a satisfying assignment or not.  For example, say the formula is: (x1 or x2 or x3) and (x1 or n(x2) or n(x3)) and (n(x1) or x2 or n(x3)) and (n(x1) or n(x2) or n(x3)) and (n(x1) or x2 or x3) and (x1 or n(x2) or x3) and (x1 or n(x2) or n(x3)) and (n(x1) or x2 or n(x3))  Here n(x1) represents the negation of x1. So, if x1 is true, then n(x1) is false, and vice versa. Algorithms NP-Completeness 21 SAT
  • 22. 22 Suppose we are given a NTM N and a string w of length n which is decided by N in f(n) or fewer nondeterministic steps. Then there is an explicit CNF formula f of length O (f(n)3) which is satisfiable iff N accepts w. In particular, when f(n) is a polynomial, f has polynomial length in terms of n so that every language in NP reduces to CSAT in polynomial time. Thus CSAT is NP-hard. Finally, as CSAT is in NP, CSAT is NP-complete. Algorithms NP-Completeness COOK - LEVIN THEOREM
  • 23. To show that X is NP-Complete: 1. Show that X is in NP, i.e., a polynomial time verifier exists for X. 2. Pick a suitable known NP-complete problem, S (ex: SAT) 3. Show a polynomial algorithm to transform an instance of S into an instance of X SOX RESTOX mnemonic can help. SAT Outside the Box Reduce SAT To X Algorithms NP-Completeness 23 NP-COMPLETENESS PROOF METHOD
  • 24. To show that X is NP-Complete: 1. Show that X is in NP, i.e., a polynomial time verifier exists for X. 2. Pick a suitable known NP-complete problem, S (ex: SAT) 3. Show a polynomial algorithm to transform an instance of S into an instance of X a) Draw the boxes, including inputs and outputs b) Write relationship between the inputs c) Describe the transformation Algorithms NP-Completeness 24 NP-COMPLETENESS PROOF METHOD (CONT.)
  • 25. Input for Problem B Output for Problem B Reduction from B to A Algorithm for A x R(x) Yes/No  Algorithm for Problem B Algorithms NP-Completeness 25 REDUCIBILITY Problem A is at least as hard as Problem B.
  • 26.  CLIQUE = { <G,k> | G is a graph with a clique of size k }  A clique is a subset of vertices that are all connected  Why is CLIQUE in NP? Algorithms NP-Completeness 26 EXAMPLE: CLIQUE
  • 27. Textbook Section 9.5.1  Pick an instance of 3-SAT, Φ, with k clauses  Make a vertex for each literal  Connect each vertex to the literals in other clauses that are not the negation  Any k-clique in this graph corresponds to a satisfying assignment Algorithms NP-Completeness 27 REDUCING 3-SAT TO CLIQUE
  • 28. Algorithms NP-Completeness 28 REDUCING 3-SAT TO CLIQUE (CONT.)
  • 29.  INDEPENDENT SET = { <G,k> | where G has an independent set of size k }  An independent set is a set of vertices, such that there are no edge between any two vertices in that set (two people are “independent” if they do not know each other).  How can we reduce the clique problem to IS? Algorithms NP-Completeness 29 EXAMPLE: INDEPENDENT SET (IS)
  • 30.  This is the dual problem!  Complement of a graph: Same vertices, but “reversed” edges – remove the ones that exist, and add the ones that don’t. Algorithms NP-Completeness 30 CLIQUE TO INDEPENDENT SET
  • 31. HAMILTONIAN PATH TO HAMILTONIAN CYCLE Algorithms NP-Completeness 31  Given a graph G = (V,E), construct a graph G’ = (V’,E’), such that:  V’ = V union {z}  E’ = E union {(z,v) | all v in V}  G’ has one more vertex, and n more edges  Claim:  G has a Hamiltonian Path if and only if G’ has a Hamiltonian Cycle
  • 32. HAMILTONIAN CYCLE TO HAMILTONIAN PATH Algorithms NP-Completeness 32  Given a graph G = (V,E), construct a graph G’ = (V’,E’), such that:  V’ = V union {z, w, x}  E’ = E union new edges.  Firstly, select a random edge {u,v} in E.  {w,u}  {x,v} for all v connected to u.  {z,x} [Thus, G’ has 3 more vertices, and a few more edges]  Claim:  G has a Hamiltonian Cycle if and only if G’ has a Hamiltonian Path
  • 33.  Algorithm for Independent Set Algorithms NP-Completeness 33 INDEPENDENT SET TO VERTEX COVER Input for Independent Set Output for Independent Set Transformation G’ = G Algorithm for Vertex Cover G,k G’,n-k Yes/No
  • 34.  Show the following polynomial time reductions  Independent Set P Vertex Cover  Vertex Cover P Dominating Set  3-SAT P Vertex Cover  Hamiltonian Cycle P Hamiltonian Path Algorithms NP-Completeness 34 PRACTICE NP-COMPLETENESS REDUCTIONS
  • 35.  NP complete problems are the HARDEST problems in NP  Reducibility – Art of reducing one problem to another  Any problem in NP can be reduced to any NP- complete problem in polynomial time.  Is P = NP? This is one of the most fascinating question in Computer Science today, with phenomenal impacts if proven in affirmative.  Reducing problems can be hard, takes practice  SAT and 3-SAT are one of the earlier known NP- complete problems, today there are thousands. Algorithms NP-Completeness 35 SUMMARY
  • 36.  To prove a problem X is NP-complete, remember to do two things:  Show X is in NP  Take a well known NP-complete problem, such as SAT, and reduce SAT to X.  SOX RESTOX mnemonic may help Algorithms NP-Completeness 36 SUMMARY