SlideShare a Scribd company logo
1 of 47
© 2020 Wael Badawy
1
More NP-complete Problems
1
DISCLAIMER:
This video is optimized for HD large display using
patented and patent-pending “Nile Codec”, the first
Egyptian Video Codec for more information,
PLEASE check https://NileCodec.com
Also available as a PodCast
© 2020 Wael Badawy
Copyright © 2020 Wael Badawy. All rights reserved
 This video is subject to copyright owned by Wael Badawy “WB”. Any
reproduction or republication of all or part of this video is expressly prohibited
unless WB has explicitly granted its prior written consent. All other rights
reserved.
 This video is intended for education and information only and is offered AS IS,
without any warranty of the accuracy or the quality of the content. Any other
use is strictly prohibited. The viewer is fully responsible to verify the accuracy
of the contents received without any claims of costs or liability arising .
 The names, trademarks service marked as logos of WB or the sponsors
appearing in this video may not be used in any any product or service,
without prior express written permission from WB and the video sponsors
 Neither WB nor any party involved in creating, producing or delivering
information and material via this video shall be liable for any direction,
incidental, consequential, indirect of punitive damages arising out of access
to, use or inability to use this content or any errors or omissions in the
content thereof.
 If you will continue to watch this video, you agree to the terms above and
other terms that may be available on http://nu.edu.eg & https://caiwave.net
2
© 2020 Wael Badawy
© 2020 Wael Badawy
4
Theorem:
If: Language is NP-complete
Language is in NP
is polynomial time reducible to
A
A B
B
Then: is NP-completeB
(proven in previous class)
© 2020 Wael Badawy
5
Using the previous theorem,
we will prove that 2 problems
are NP-complete:
Vertex-Cover
Hamiltonian-Path
© 2020 Wael Badawy
Vertex Cover
S
6
Vertex cover of a graph
is a subset of nodes such that every edge
in the graph touches one node in S
S = red nodes
Example:
© 2020 Wael Badawy
7
|S|=4Example:
Size of vertex-cover
is the number of nodes in the cover
© 2020 Wael Badawy
8
graph contains a vertex cover
of size }
VERTEX-COVER = { :kG,
G
k
Corresponding language:
Example:
G 
COVER-VERTEX4, G
© 2020 Wael Badawy
9
Theorem:
1. VERTEX-COVER is in NP
2. We will reduce in polynomial time
3CNF-SAT to VERTEX-COVER
Can be easily proven
VERTEX-COVER is NP-complete
Proof:
(NP-complete)
© 2020 Wael Badawy
10
Let be a 3CNF formula
with variables
and clauses

m
l
Example:
)()()( 431421321 xxxxxxxxx 
4m
3l
Clause 1 Clause 2 Clause 3
© 2020 Wael Badawy
11
Formula can be converted
to a graph such that:

G
 is satisfied
if and only if
G Contains a vertex cover
of size lmk 2
© 2020 Wael Badawy
12
)()()( 431421321 xxxxxxxxx 
1x 1x 2x 2x 3x 3x 4x 4x
1x
2x 3x
1x
2x 4x
1x
3x 4x
Clause 1 Clause 2 Clause 3
Clause 1 Clause 2 Clause 3
Variable Gadgets
Clause Gadgets
m2 nodes
l3 nodes
© 2020 Wael Badawy
13
)()()( 431421321 xxxxxxxxx 
1x 1x 2x 2x 3x 3x 4x 4x
1x
2x 3x
1x
2x 4x
1x
3x 4x
Clause 1 Clause 2 Clause 3
Clause 1 Clause 2 Clause 3
© 2020 Wael Badawy
14
If is satisfied,
then contains a vertex cover of size

G
lmk 2
First direction in proof:
© 2020 Wael Badawy
15
)()()( 431421321 xxxxxxxxx 
Satisfying assignment
1001 4321  xxxx
Example:
We will show that contains
a vertex cover of size
103242  lmk
G
© 2020 Wael Badawy
16
)()()( 431421321 xxxxxxxxx 
1x 1x 2x 2x 3x 3x 4x 4x
1x
2x 3x
1x
2x 4x
1x
3x 4x
1001 4321  xxxx
Put every satisfying literal in the cover
© 2020 Wael Badawy
17
)()()( 431421321 xxxxxxxxx 
1x 1x 2x 2x 3x 3x 4x 4x
1x
2x 3x
1x
2x 4x
1x
3x 4x
1001 4321  xxxx
Select one satisfying literal in each clause gadget
and include the remaining literals in the cover
© 2020 Wael Badawy
18
1x 1x 2x 2x 3x 3x 4x 4x
1x
2x 3x
1x
2x 4x
1x
3x 4x
This is a vertex cover since every edge is
adjacent to a chosen node
© 2020 Wael Badawy
19
Explanation for general case:
1x 1x 2x 2x 3x 3x 4x 4x
Edges in variable gadgets
are incident to at least one node in cover
© 2020 Wael Badawy
20
1x
2x 3x
1x
2x 4x
1x
3x 4x
Edges in clause gadgets
are incident to at least one node in cover,
since two nodes are chosen in a clause gadget
© 2020 Wael Badawy
21
1x 1x 2x 2x 3x 3x 4x 4x
1x
2x 3x
1x
2x 4x
1x
3x 4x
Every edge connecting variable gadgets
and clause gadgets is one of three types:
Type 1 Type 2 Type 3
All adjacent to nodes in cover
© 2020 Wael Badawy
22
If graph contains a vertex-cover
of size
then formula is satisfiable
G

lmk 2
Second direction of proof:
© 2020 Wael Badawy
23
Example:
1x 1x 2x 2x 3x 3x 4x 4x
1x
2x 3x
1x
2x 4x
1x
3x 4x
© 2020 Wael Badawy
24
1x 1x 2x 2x 3x 3x 4x 4x
1x
2x 3x
1x
2x 4x
1x
3x 4x
exactly one literal in each variable gadget is chosen
exactly two nodes in each clause gadget is chosen
To include “internal’’ edges to gadgets,
and satisfy lmk 2
m chosen out of m2
l2 l3chosen out of
© 2020 Wael Badawy
25
For the variable assignment choose the
literals in the cover from variable gadgets
1x 1x 2x 2x 3x 3x 4x 4x
1001 4321  xxxx
)()()( 431421321 xxxxxxxxx 
© 2020 Wael Badawy
26
1x 1x 2x 2x 3x 3x 4x 4x
1x
2x 3x
1x
2x 4x
1x
3x 4x
1001 4321  xxxx
)()()( 431421321 xxxxxxxxx 
since the respective literals satisfy the clauses
is satisfied with
© 2020 Wael Badawy
27
1x 1x
1x
2x 3x
It is impossible to have this scenario
because one edge wouldn’t be covered
3x 3x2x 2x
© 2020 Wael Badawy
28
End of proof
The proof can be generalized for arbitrary 
we have reduced in polynomial time
3CNF-SAT to VERTEX-COVER
Therefore:
The graph is constructed in polynomial
time with respect to the size of
G

© 2020 Wael Badawy
29
Theorem:
1. HAMILTONIAN-PATH is in NP
2. We will reduce in polynomial time
3CNF-SAT to HAMILTONIAN-PATH
Can be easily proven
HAMILTONIAN-PATH
is NP-complete
Proof:
(NP-complete)
© 2020 Wael Badawy
30
)()( 2121 xxxx 
Consider an arbitrary CNF formula
Whatever we will do applies to
3CNF formulas as well
© 2020 Wael Badawy
31
Gadget for
variable 1x
33 lNumber of nodes in row:
for clausesl
)()( 2121 xxxx 
© 2020 Wael Badawy
32
)()( 2121 xxxx 
)( 21 xx 
)( 21 xx 
Gadget for
variable 1x
clause node
clause node
A pair of nodes in gadget for each clause node;
Pairs separated by a node
pair 1 pair 2
© 2020 Wael Badawy
33
)()( 2121 xxxx 
Gadget for
variable
)( 21 xx 
clause node
If variable appears as is in clause:
first edge from gadget outgoing (left to right)
second edge from gadget incoming
pair 1
1x
© 2020 Wael Badawy
34
)()( 2121 xxxx 
)( 21 xx 
Gadget for
variable 1x
the directions change
clause node
pair 2
If variable appears inverted in clause:
first edge from gadget incoming (left to right)
second edge from gadget outgoing
© 2020 Wael Badawy
35
)()( 2121 xxxx 
)( 21 xx 
)( 21 xx 
Gadget for
variable 1x
clause node
clause node
pair 1 pair 2
© 2020 Wael Badawy
36
)()( 2121 xxxx 
)( 21 xx 
)( 21 xx 
Gadget for
variable
clause node
clause node
pair 1 pair 2
2x
© 2020 Wael Badawy
37
)( 21 xx 
)( 21 xx 
1x
2x
)()( 2121 xxxx 
Complete Graph
© 2020 Wael Badawy
38
1)()( 2121  xxxx
Satisfying assignment: 11 x 12 x
Satisfying assignment: 01 x 12 x
© 2020 Wael Badawy
39
)( 21 xx 
)( 21 xx 
11 x
1)()( 2121  xxxx
Hamiltonian
path
If variable is set to 1 traverse its gadget
from left to right
Visit clauses satisfied from the variable assignment
Gadget for 1x
© 2020 Wael Badawy
40
)( 21 xx 
)( 21 xx 
01 x
1)()( 2121  xxxx
Hamiltonian
path
If variable is set to 0 traverse its gadget
from right to left
Visit clauses satisfied from the variable assignment
Gadget for 1x
© 2020 Wael Badawy
41
)( 21 xx 
)( 21 xx 
11 x
12 x
1)()( 2121  xxxx
A satisfying
assignment
Hamiltonian
path
© 2020 Wael Badawy
42
)( 21 xx 
)( 21 xx 
01 x
12 x
1)()( 2121  xxxx
Another satisfying
assignment
Hamiltonian
path
© 2020 Wael Badawy
43
For each clause pick one variable that
satisfies it and visit respective node once
from that variable gadget
)( 21 xx 
)( 21 xx 
11 x
12 x
1)()( 2121  xxxx
© 2020 Wael Badawy
44
if the graph has a Hamiltonian path,
then the formula has a satisfying assignment
Each clause node is visited exactly once
from some variable gadget, and that variable
satisfies the clause
Symmetrically, it can also be shown:
Basic idea:
© 2020 Wael Badawy
45
)( 21 xx 
)( 21 xx 
It is impossible a clause node to be traversed
from different variable gadgets
Node not visited
Node repeated
© 2020 Wael Badawy
46
Therefore:
The formula is satisfied if and only if
the respective graph has a Hamiltonian path
© 2020 Wael Badawy
47
End of proof
The proof can apply to any 3CNF formula
we have reduced in polynomial time
3CNF-SAT to HAMILTONIAN-PATH
Therefore:
The graph is constructed in polynomial
time with respect to the size of the formula

More Related Content

Similar to Np complete reductions

Universal turing
Universal turing Universal turing
Universal turing Wael Badawy
 
Boosting Vertex-Cut Partitioning for Streaming Graphs
Boosting Vertex-Cut Partitioning for Streaming GraphsBoosting Vertex-Cut Partitioning for Streaming Graphs
Boosting Vertex-Cut Partitioning for Streaming GraphsHooman Peiro Sajjad
 
A Fast Near Optimal Vertex Cover Algorithm (NOVCA)
A Fast Near Optimal Vertex Cover Algorithm (NOVCA)A Fast Near Optimal Vertex Cover Algorithm (NOVCA)
A Fast Near Optimal Vertex Cover Algorithm (NOVCA)Waqas Tariq
 
Computer Vision RANSAC
Computer Vision RANSACComputer Vision RANSAC
Computer Vision RANSACWael Badawy
 
CEM Workshop Lectures (6/11): FVTD Method in CEM
CEM Workshop Lectures (6/11): FVTD Method in CEMCEM Workshop Lectures (6/11): FVTD Method in CEM
CEM Workshop Lectures (6/11): FVTD Method in CEMAbhishek Jain
 

Similar to Np complete reductions (6)

Turing Machine
Turing MachineTuring Machine
Turing Machine
 
Universal turing
Universal turing Universal turing
Universal turing
 
Boosting Vertex-Cut Partitioning for Streaming Graphs
Boosting Vertex-Cut Partitioning for Streaming GraphsBoosting Vertex-Cut Partitioning for Streaming Graphs
Boosting Vertex-Cut Partitioning for Streaming Graphs
 
A Fast Near Optimal Vertex Cover Algorithm (NOVCA)
A Fast Near Optimal Vertex Cover Algorithm (NOVCA)A Fast Near Optimal Vertex Cover Algorithm (NOVCA)
A Fast Near Optimal Vertex Cover Algorithm (NOVCA)
 
Computer Vision RANSAC
Computer Vision RANSACComputer Vision RANSAC
Computer Vision RANSAC
 
CEM Workshop Lectures (6/11): FVTD Method in CEM
CEM Workshop Lectures (6/11): FVTD Method in CEMCEM Workshop Lectures (6/11): FVTD Method in CEM
CEM Workshop Lectures (6/11): FVTD Method in CEM
 

More from Wael Badawy

HTML introduction
HTML introduction HTML introduction
HTML introduction Wael Badawy
 
Computer Vision Cameras
Computer Vision CamerasComputer Vision Cameras
Computer Vision CamerasWael Badawy
 
Computer Vision Gans
Computer Vision GansComputer Vision Gans
Computer Vision GansWael Badawy
 
Computer Vision image classification
Computer Vision image classificationComputer Vision image classification
Computer Vision image classificationWael Badawy
 
Computer Vision Structure from motion
Computer Vision Structure from motionComputer Vision Structure from motion
Computer Vision Structure from motionWael Badawy
 
Regular pumping examples
Regular pumping examples Regular pumping examples
Regular pumping examples Wael Badawy
 
Pushdown Automota
Pushdown Automota Pushdown Automota
Pushdown Automota Wael Badawy
 
Pda accept context free
Pda accept context freePda accept context free
Pda accept context freeWael Badawy
 
Computer Vision sfm
Computer Vision sfmComputer Vision sfm
Computer Vision sfmWael Badawy
 
Computer vision - photometric
Computer vision - photometricComputer vision - photometric
Computer vision - photometricWael Badawy
 
Computer vision - light
Computer vision - lightComputer vision - light
Computer vision - lightWael Badawy
 
Computer vision - two view geometry
Computer vision -  two view geometryComputer vision -  two view geometry
Computer vision - two view geometryWael Badawy
 
Computer Vision - Stereo Vision
Computer Vision - Stereo VisionComputer Vision - Stereo Vision
Computer Vision - Stereo VisionWael Badawy
 
Computer Vision - Single View
Computer Vision - Single ViewComputer Vision - Single View
Computer Vision - Single ViewWael Badawy
 
Computer Vision single view Modelling
Computer Vision single view ModellingComputer Vision single view Modelling
Computer Vision single view ModellingWael Badawy
 
Computer Vision panoramas
Computer Vision  panoramasComputer Vision  panoramas
Computer Vision panoramasWael Badawy
 
Computer Vision - cameras
Computer Vision - camerasComputer Vision - cameras
Computer Vision - camerasWael Badawy
 
Computer Vision - RANSAC
Computer Vision - RANSACComputer Vision - RANSAC
Computer Vision - RANSACWael Badawy
 
Computer Vision alignment
Computer Vision alignmentComputer Vision alignment
Computer Vision alignmentWael Badawy
 

More from Wael Badawy (20)

HTML introduction
HTML introduction HTML introduction
HTML introduction
 
Parsers -
Parsers -Parsers -
Parsers -
 
Computer Vision Cameras
Computer Vision CamerasComputer Vision Cameras
Computer Vision Cameras
 
Computer Vision Gans
Computer Vision GansComputer Vision Gans
Computer Vision Gans
 
Computer Vision image classification
Computer Vision image classificationComputer Vision image classification
Computer Vision image classification
 
Computer Vision Structure from motion
Computer Vision Structure from motionComputer Vision Structure from motion
Computer Vision Structure from motion
 
Regular pumping examples
Regular pumping examples Regular pumping examples
Regular pumping examples
 
Pushdown Automota
Pushdown Automota Pushdown Automota
Pushdown Automota
 
Pda accept context free
Pda accept context freePda accept context free
Pda accept context free
 
Computer Vision sfm
Computer Vision sfmComputer Vision sfm
Computer Vision sfm
 
Computer vision - photometric
Computer vision - photometricComputer vision - photometric
Computer vision - photometric
 
Computer vision - light
Computer vision - lightComputer vision - light
Computer vision - light
 
Computer vision - two view geometry
Computer vision -  two view geometryComputer vision -  two view geometry
Computer vision - two view geometry
 
Computer Vision - Stereo Vision
Computer Vision - Stereo VisionComputer Vision - Stereo Vision
Computer Vision - Stereo Vision
 
Computer Vision - Single View
Computer Vision - Single ViewComputer Vision - Single View
Computer Vision - Single View
 
Computer Vision single view Modelling
Computer Vision single view ModellingComputer Vision single view Modelling
Computer Vision single view Modelling
 
Computer Vision panoramas
Computer Vision  panoramasComputer Vision  panoramas
Computer Vision panoramas
 
Computer Vision - cameras
Computer Vision - camerasComputer Vision - cameras
Computer Vision - cameras
 
Computer Vision - RANSAC
Computer Vision - RANSACComputer Vision - RANSAC
Computer Vision - RANSAC
 
Computer Vision alignment
Computer Vision alignmentComputer Vision alignment
Computer Vision alignment
 

Recently uploaded

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 

Recently uploaded (20)

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

Np complete reductions

  • 1. © 2020 Wael Badawy 1 More NP-complete Problems 1 DISCLAIMER: This video is optimized for HD large display using patented and patent-pending “Nile Codec”, the first Egyptian Video Codec for more information, PLEASE check https://NileCodec.com Also available as a PodCast
  • 2. © 2020 Wael Badawy Copyright © 2020 Wael Badawy. All rights reserved  This video is subject to copyright owned by Wael Badawy “WB”. Any reproduction or republication of all or part of this video is expressly prohibited unless WB has explicitly granted its prior written consent. All other rights reserved.  This video is intended for education and information only and is offered AS IS, without any warranty of the accuracy or the quality of the content. Any other use is strictly prohibited. The viewer is fully responsible to verify the accuracy of the contents received without any claims of costs or liability arising .  The names, trademarks service marked as logos of WB or the sponsors appearing in this video may not be used in any any product or service, without prior express written permission from WB and the video sponsors  Neither WB nor any party involved in creating, producing or delivering information and material via this video shall be liable for any direction, incidental, consequential, indirect of punitive damages arising out of access to, use or inability to use this content or any errors or omissions in the content thereof.  If you will continue to watch this video, you agree to the terms above and other terms that may be available on http://nu.edu.eg & https://caiwave.net 2
  • 3. © 2020 Wael Badawy
  • 4. © 2020 Wael Badawy 4 Theorem: If: Language is NP-complete Language is in NP is polynomial time reducible to A A B B Then: is NP-completeB (proven in previous class)
  • 5. © 2020 Wael Badawy 5 Using the previous theorem, we will prove that 2 problems are NP-complete: Vertex-Cover Hamiltonian-Path
  • 6. © 2020 Wael Badawy Vertex Cover S 6 Vertex cover of a graph is a subset of nodes such that every edge in the graph touches one node in S S = red nodes Example:
  • 7. © 2020 Wael Badawy 7 |S|=4Example: Size of vertex-cover is the number of nodes in the cover
  • 8. © 2020 Wael Badawy 8 graph contains a vertex cover of size } VERTEX-COVER = { :kG, G k Corresponding language: Example: G  COVER-VERTEX4, G
  • 9. © 2020 Wael Badawy 9 Theorem: 1. VERTEX-COVER is in NP 2. We will reduce in polynomial time 3CNF-SAT to VERTEX-COVER Can be easily proven VERTEX-COVER is NP-complete Proof: (NP-complete)
  • 10. © 2020 Wael Badawy 10 Let be a 3CNF formula with variables and clauses  m l Example: )()()( 431421321 xxxxxxxxx  4m 3l Clause 1 Clause 2 Clause 3
  • 11. © 2020 Wael Badawy 11 Formula can be converted to a graph such that:  G  is satisfied if and only if G Contains a vertex cover of size lmk 2
  • 12. © 2020 Wael Badawy 12 )()()( 431421321 xxxxxxxxx  1x 1x 2x 2x 3x 3x 4x 4x 1x 2x 3x 1x 2x 4x 1x 3x 4x Clause 1 Clause 2 Clause 3 Clause 1 Clause 2 Clause 3 Variable Gadgets Clause Gadgets m2 nodes l3 nodes
  • 13. © 2020 Wael Badawy 13 )()()( 431421321 xxxxxxxxx  1x 1x 2x 2x 3x 3x 4x 4x 1x 2x 3x 1x 2x 4x 1x 3x 4x Clause 1 Clause 2 Clause 3 Clause 1 Clause 2 Clause 3
  • 14. © 2020 Wael Badawy 14 If is satisfied, then contains a vertex cover of size  G lmk 2 First direction in proof:
  • 15. © 2020 Wael Badawy 15 )()()( 431421321 xxxxxxxxx  Satisfying assignment 1001 4321  xxxx Example: We will show that contains a vertex cover of size 103242  lmk G
  • 16. © 2020 Wael Badawy 16 )()()( 431421321 xxxxxxxxx  1x 1x 2x 2x 3x 3x 4x 4x 1x 2x 3x 1x 2x 4x 1x 3x 4x 1001 4321  xxxx Put every satisfying literal in the cover
  • 17. © 2020 Wael Badawy 17 )()()( 431421321 xxxxxxxxx  1x 1x 2x 2x 3x 3x 4x 4x 1x 2x 3x 1x 2x 4x 1x 3x 4x 1001 4321  xxxx Select one satisfying literal in each clause gadget and include the remaining literals in the cover
  • 18. © 2020 Wael Badawy 18 1x 1x 2x 2x 3x 3x 4x 4x 1x 2x 3x 1x 2x 4x 1x 3x 4x This is a vertex cover since every edge is adjacent to a chosen node
  • 19. © 2020 Wael Badawy 19 Explanation for general case: 1x 1x 2x 2x 3x 3x 4x 4x Edges in variable gadgets are incident to at least one node in cover
  • 20. © 2020 Wael Badawy 20 1x 2x 3x 1x 2x 4x 1x 3x 4x Edges in clause gadgets are incident to at least one node in cover, since two nodes are chosen in a clause gadget
  • 21. © 2020 Wael Badawy 21 1x 1x 2x 2x 3x 3x 4x 4x 1x 2x 3x 1x 2x 4x 1x 3x 4x Every edge connecting variable gadgets and clause gadgets is one of three types: Type 1 Type 2 Type 3 All adjacent to nodes in cover
  • 22. © 2020 Wael Badawy 22 If graph contains a vertex-cover of size then formula is satisfiable G  lmk 2 Second direction of proof:
  • 23. © 2020 Wael Badawy 23 Example: 1x 1x 2x 2x 3x 3x 4x 4x 1x 2x 3x 1x 2x 4x 1x 3x 4x
  • 24. © 2020 Wael Badawy 24 1x 1x 2x 2x 3x 3x 4x 4x 1x 2x 3x 1x 2x 4x 1x 3x 4x exactly one literal in each variable gadget is chosen exactly two nodes in each clause gadget is chosen To include “internal’’ edges to gadgets, and satisfy lmk 2 m chosen out of m2 l2 l3chosen out of
  • 25. © 2020 Wael Badawy 25 For the variable assignment choose the literals in the cover from variable gadgets 1x 1x 2x 2x 3x 3x 4x 4x 1001 4321  xxxx )()()( 431421321 xxxxxxxxx 
  • 26. © 2020 Wael Badawy 26 1x 1x 2x 2x 3x 3x 4x 4x 1x 2x 3x 1x 2x 4x 1x 3x 4x 1001 4321  xxxx )()()( 431421321 xxxxxxxxx  since the respective literals satisfy the clauses is satisfied with
  • 27. © 2020 Wael Badawy 27 1x 1x 1x 2x 3x It is impossible to have this scenario because one edge wouldn’t be covered 3x 3x2x 2x
  • 28. © 2020 Wael Badawy 28 End of proof The proof can be generalized for arbitrary  we have reduced in polynomial time 3CNF-SAT to VERTEX-COVER Therefore: The graph is constructed in polynomial time with respect to the size of G 
  • 29. © 2020 Wael Badawy 29 Theorem: 1. HAMILTONIAN-PATH is in NP 2. We will reduce in polynomial time 3CNF-SAT to HAMILTONIAN-PATH Can be easily proven HAMILTONIAN-PATH is NP-complete Proof: (NP-complete)
  • 30. © 2020 Wael Badawy 30 )()( 2121 xxxx  Consider an arbitrary CNF formula Whatever we will do applies to 3CNF formulas as well
  • 31. © 2020 Wael Badawy 31 Gadget for variable 1x 33 lNumber of nodes in row: for clausesl )()( 2121 xxxx 
  • 32. © 2020 Wael Badawy 32 )()( 2121 xxxx  )( 21 xx  )( 21 xx  Gadget for variable 1x clause node clause node A pair of nodes in gadget for each clause node; Pairs separated by a node pair 1 pair 2
  • 33. © 2020 Wael Badawy 33 )()( 2121 xxxx  Gadget for variable )( 21 xx  clause node If variable appears as is in clause: first edge from gadget outgoing (left to right) second edge from gadget incoming pair 1 1x
  • 34. © 2020 Wael Badawy 34 )()( 2121 xxxx  )( 21 xx  Gadget for variable 1x the directions change clause node pair 2 If variable appears inverted in clause: first edge from gadget incoming (left to right) second edge from gadget outgoing
  • 35. © 2020 Wael Badawy 35 )()( 2121 xxxx  )( 21 xx  )( 21 xx  Gadget for variable 1x clause node clause node pair 1 pair 2
  • 36. © 2020 Wael Badawy 36 )()( 2121 xxxx  )( 21 xx  )( 21 xx  Gadget for variable clause node clause node pair 1 pair 2 2x
  • 37. © 2020 Wael Badawy 37 )( 21 xx  )( 21 xx  1x 2x )()( 2121 xxxx  Complete Graph
  • 38. © 2020 Wael Badawy 38 1)()( 2121  xxxx Satisfying assignment: 11 x 12 x Satisfying assignment: 01 x 12 x
  • 39. © 2020 Wael Badawy 39 )( 21 xx  )( 21 xx  11 x 1)()( 2121  xxxx Hamiltonian path If variable is set to 1 traverse its gadget from left to right Visit clauses satisfied from the variable assignment Gadget for 1x
  • 40. © 2020 Wael Badawy 40 )( 21 xx  )( 21 xx  01 x 1)()( 2121  xxxx Hamiltonian path If variable is set to 0 traverse its gadget from right to left Visit clauses satisfied from the variable assignment Gadget for 1x
  • 41. © 2020 Wael Badawy 41 )( 21 xx  )( 21 xx  11 x 12 x 1)()( 2121  xxxx A satisfying assignment Hamiltonian path
  • 42. © 2020 Wael Badawy 42 )( 21 xx  )( 21 xx  01 x 12 x 1)()( 2121  xxxx Another satisfying assignment Hamiltonian path
  • 43. © 2020 Wael Badawy 43 For each clause pick one variable that satisfies it and visit respective node once from that variable gadget )( 21 xx  )( 21 xx  11 x 12 x 1)()( 2121  xxxx
  • 44. © 2020 Wael Badawy 44 if the graph has a Hamiltonian path, then the formula has a satisfying assignment Each clause node is visited exactly once from some variable gadget, and that variable satisfies the clause Symmetrically, it can also be shown: Basic idea:
  • 45. © 2020 Wael Badawy 45 )( 21 xx  )( 21 xx  It is impossible a clause node to be traversed from different variable gadgets Node not visited Node repeated
  • 46. © 2020 Wael Badawy 46 Therefore: The formula is satisfied if and only if the respective graph has a Hamiltonian path
  • 47. © 2020 Wael Badawy 47 End of proof The proof can apply to any 3CNF formula we have reduced in polynomial time 3CNF-SAT to HAMILTONIAN-PATH Therefore: The graph is constructed in polynomial time with respect to the size of the formula

Editor's Notes

  1. 1