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

La actualidad más candente (20)

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 chapter 10
Algorithm chapter 10Algorithm chapter 10
Algorithm chapter 10
 
Np hard
Np hardNp hard
Np hard
 
Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
P vs NP
P vs NP P vs NP
P vs NP
 
Tsp is NP-Complete
Tsp is NP-CompleteTsp is NP-Complete
Tsp is NP-Complete
 
Approximation Algorithms
Approximation AlgorithmsApproximation Algorithms
Approximation Algorithms
 
Parallel algorithms
Parallel algorithmsParallel algorithms
Parallel algorithms
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
A greedy algorithms
A greedy algorithmsA greedy algorithms
A greedy algorithms
 
Unit 1 chapter 1 Design and Analysis of Algorithms
Unit 1   chapter 1 Design and Analysis of AlgorithmsUnit 1   chapter 1 Design and Analysis of Algorithms
Unit 1 chapter 1 Design and Analysis of Algorithms
 
Formal Languages and Automata Theory Unit 1
Formal Languages and Automata Theory Unit 1Formal Languages and Automata Theory Unit 1
Formal Languages and Automata Theory Unit 1
 
5.5 back track
5.5 back track5.5 back track
5.5 back track
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 

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 Design and Analysis of Algorithms: 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
 
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
 
Basic_concepts_NP_Hard_NP_Complete.pdf
Basic_concepts_NP_Hard_NP_Complete.pdfBasic_concepts_NP_Hard_NP_Complete.pdf
Basic_concepts_NP_Hard_NP_Complete.pdfArivukkarasu Dhanapal
 
Design and Analysis of Algorithms Exam Help
Design and Analysis of Algorithms Exam HelpDesign and Analysis of Algorithms Exam Help
Design and Analysis of Algorithms Exam HelpProgramming Exam Help
 

Similar a Design and Analysis of Algorithms: 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
 
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
 
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
 
Basic_concepts_NP_Hard_NP_Complete.pdf
Basic_concepts_NP_Hard_NP_Complete.pdfBasic_concepts_NP_Hard_NP_Complete.pdf
Basic_concepts_NP_Hard_NP_Complete.pdf
 
Design and Analysis of Algorithms Exam Help
Design and Analysis of Algorithms Exam HelpDesign and Analysis of Algorithms Exam Help
Design and Analysis of Algorithms Exam Help
 

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
 
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
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresAmrinder 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
 
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
 
R-Trees and Geospatial Data Structures
R-Trees and Geospatial Data StructuresR-Trees and Geospatial Data Structures
R-Trees and Geospatial Data Structures
 

Último

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 

Último (20)

A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 

Design and Analysis of Algorithms: 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