SlideShare uma empresa 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

Mais conteúdo relacionado

Mais procurados

Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Ehtisham Ali
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 

Mais procurados (20)

Np hard
Np hardNp hard
Np hard
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and bound
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Recurrences
RecurrencesRecurrences
Recurrences
 
Master method
Master method Master method
Master method
 
Daa notes 1
Daa notes 1Daa notes 1
Daa notes 1
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
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
 
Time complexity
Time complexityTime complexity
Time complexity
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Boyer moore algorithm
Boyer moore algorithmBoyer moore algorithm
Boyer moore algorithm
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
02 order of growth
02 order of growth02 order of growth
02 order of growth
 
Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approach
 
Theory of Computation Lecture Notes
Theory of Computation Lecture NotesTheory of Computation Lecture Notes
Theory of Computation Lecture Notes
 
simple problem to convert NFA with epsilon to without epsilon
simple problem to convert NFA with epsilon to without epsilonsimple problem to convert NFA with epsilon to without epsilon
simple problem to convert NFA with epsilon to without epsilon
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 

Destaque (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
 

Semelhante 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 ppt
JyoReddy9
 
2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou
vafopoulos
 

Semelhante 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
 
NP Complete Problems in Graph Theory
NP Complete Problems in Graph TheoryNP Complete Problems in Graph Theory
NP Complete Problems in Graph Theory
 
Internship
InternshipInternship
Internship
 
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
 
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
 
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
 

Mais de Amrinder Arora

Mais 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

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

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