










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These are the Lecture Slides of Algorithm and Complexity Analysis which includes Approximation Algorithms, Coping with Np-Hardness, Fully Polynomial-Time, Brute-Force Algorithms, Approximation Scheme, Knapsack Problem, Profit Subset of Items, Nonnegative Values etc. Key important points are:Polynomial-Time Reductions, Simple Equivalence, Time Oracle, Cook-Turing Reducibility, Standard Computational Steps, Compositeness and Primality, Vertex Cover, Primality Testing and Factoring
Typology: Slides
1 / 18
This page cannot be seen from the preview
Don't miss anything!











Contents.^ n^ Polynomial-time reductions.^ n^ Reduction from special case to general case.^ –^ COMPOSITE reduces to FACTOR^ –^ VERTEX-COVER reduces to SET-COVER^ n^ Reduction by simple equivalence.^ –^ PRIMALITY reduces to COMPOSITE, and vice versa^ –^ VERTEX COVER reduces to CLIQUE, and vice versa^ n^ Reduction from general case to special case.^ –^ SAT reduces to 3-SAT^ –^ 3-COLOR reduces to PLANAR-3-COLOR^ n^ Reduction by encoding with gadgets.^ –^ 3-CNF-SAT reduces to CLIQUE^ –^ 3-CNF-SAT reduces to HAM-CYCLE^ –^ 3-CNF-SAT reduces to 3-COLOR 3
Intuitively, problem X reduces to problem Y if:^ n^ Any instance of X can be "rephrased" as an instance of Y.Formally, problem X polynomial reduces to problem Y if arbitraryinstances of problem X can be solved using:^ n^ Polynomial number of standard computational steps, plus^ n^ Polynomial number of calls to oracle that solves problem Y.^ –^ computational model supplemented by special piece ofhardware that solves instances of Y in a single stepRemarks.^ n^ We pay for time to write down instances sent to black box
instances of Y are of polynomial size. n Note: Cook-Turing reducibility (not Karp or many-to-one). n Notation: X
≤^ Y (or more preciselyP^
Purpose. Classify problems according to relative difficulty.Design algorithms. If X
≤^ Y and Y can be solved in polynomial-time,P^ then X can be solved in polynomial time.Establish intractability. If X
≤^ Y and X cannot be solved inP^
polynomial-time, then X cannot be solved in polynomial time.Anti-symmetry. If X
≤^ Y and YP^
≤^ X, we use notation XP^
Transitivity. If X
≤^ Y and YP^
≤^ Z, then XP^
n^ Proof idea: compose the two algorithms. n^ Given an oracle for Z, can solve instance of X:^ –^ run the algorithm for X using a oracle for Y^ –^ each time oracle for Y is called, simulate it in a polynomialnumber of steps by using algorithm for Y, plus oracle calls to Z
5
Polynomial-Time Reduction Basic strategies.^ n^ Reduction by simple equivalence.^ n^ Reduction from special case to general case.^ n^ Reduction from general case to special case.^ n^ Reduction by encoding with gadgets.
Compositeness and Primality COMPOSITE: Given the decimal representation of an integer x, does xhave a nontrivial factor?PRIME: Given the decimal representation of an integer x, is x prime?Claim. COMPOSITE
n^ COMPOSITE
n^ PRIME ≤^ COMPOSITE.P^ COMPOSITE (x) IF (PRIME(x) = TRUE)RETURN FALSEELSERETURN TRUE
IF (COMPOSITE(x) = TRUE)RETURN FALSEELSERETURN TRUE
PRIME (x)
7
3
(^6710)
Vertex Cover VERTEX COVER: Given an undirected graph G = (V, E) and an integerk, is there a subset of vertices S
⊆^ V such that |S|
≤^ k, and if (v, w)
then either v
∈^ S, w^ ∈
S or both. Ex.^ n^ Is there a vertex cover of size 4?
1 5
8 2 4
9 3
(^6710)
3
(^6710)
Vertex Cover VERTEX COVER: Given an undirected graph G = (V, E) and an integerk, is there a subset of vertices S
⊆^ V such that |S|
≤^ k, and if (v, w)
then either v
∈^ S, w^ ∈
S or both. Ex.^ n^ Is there a vertex cover of size 4?^ n^ Is there a vertex cover of size 3?
1 5
8 2 4
9
Docsity.com
13
Polynomial-Time Reduction Basic strategies.^ n^ Reduction by simple equivalence.^ n^ Reduction from special case to general case.^ n^ Reduction from general case to special case.^ n^ Reduction by encoding with gadgets.
Compositeness Reduces to FactoringCOMPOSITE: Given an integer x, does x have a nontrivial factor?FACTOR: Given two integers x and y, does x have a nontrivial factorless than y?Claim. COMPOSITE
Proof. Given an oracle for FACTOR, we solve COMPOSITE.^ n^ Is 350 composite?^ n^ Does 350 have a nontrivial factorless than 350?
COMPOSITE (x) IF (FACTOR(x, x) = TRUE)RETURN TRUEELSERETURN FALSE
15
Primality Testing and Factoring We established:^ n^ PRIME
Natural question:^ n^ Does FACTOR
n^ Consensus opinion = NO.State-of-the-art. n^ PRIME in randomized P and conjectured to be in P. n^ FACTOR not believed to be in P.RSA cryptosystem. n^ Based on dichotomy between two problems. n^ To use, must generate large primes efficiently. n^ Can break with efficient factoring algorithm.
Set Cover
SET COVER: Given a set U of elements, a collection S
ofm
subsets of U, and an integer k, does there exist a collection of at mostk of these sets whose union is equal of U?Sample application.^ n^ n available pieces of software.^ n^ Set U of n capabilities that we would like our system to have.^ n^ The ith piece of software provides the set S
⊆^ U of capabilities.i
n^ Goal: achieve all n capabilities using small number of pieces ofsoftware.Ex. U = {1, 2, 3,... , 12}, k = 3. n^ S= {1, 2, 3, 4, 5, 6}^1
n^ S= {1, 4, 7, 10}^3
n^ S= {3, 6, 9, 12}^5
Docsity.com
17
Vertex Cover Reduces to Set Cover SET COVER: Given a set U of elements, a collection S
ofn’
subsets of U, and an integer k, does there exist a collection of at mostk of these sets whose union is equal to U?VERTEX COVER: Given an undirected graph G = (V, E) and an integerk, is there a subset of vertices S
⊆^ V such that |S|
≤^ k, and if (v, w)
then either v
∈^ S, w^ ∈
S or both. Claim. VERTEX-COVER
Proof. Given black box that solves instances of SET-COVER.
a
b d f^ e
c
Vertex Cover
U = {1, 2, 3, 4, 5, 6, 7}k = 2S= {3, 7}a^
S^ b
S= {3, 4, 5, 6}c^
S= {5}d^ S= {1}^ e^
S= {1, 2, 6, 7}f^ Set Cover
G = (V, E)k = 2
e^2 e 1 ee^34 e 6 e^5 e^7
Vertex Cover Reduces to Set Cover SET COVER: Given a set U of elements, a collection S
ofn’
subsets of U, and an integer k, does there exist a collection of at mostk of these sets whose union is equal to U?VERTEX COVER: Given an undirected graph G = (V, E) and an integerk, is there a subset of vertices S
⊆^ V such that |S|
≤^ k, and if (v, w)
then either v
∈^ S, w^ ∈
S or both. Claim. VERTEX-COVER
Proof. Given black box that solves instances of SET-COVER.^ n^ Let G = (V, E), k be an instance of VERTEX-COVER.^ n^ Create SET-COVER instance:^ –^ k = k, U = E, S
= {e^ ∈^ E : e incident to v }v n^ Set-cover of size at most k if and only if vertex cover of size atmost k. 19
Polynomial-Time Reduction Basic strategies.^ n^ Reduction by simple equivalence.^ n^ Reduction from special case to general case.^ n^ Reduction from general case to special case.^ n^ Reduction by encoding with gadgets.
Factoring and Finding Factors FACTOR: Given two integers x and y, does x have a nontrivial factorless than y?FACTORIZE: Given an integer x, find its prime factorization.Claim. FACTORIZE
Proof: FACTOR
n^ Reduction from special case to general case.
S^ ←^ FACTORIZE(x)d^ ←^ smallest factor in SIF (d < y)RETURN TRUEELSERETURN FALSE
FACTOR (x)
S = prime factorizationis of polynomial size
Docsity.com
25
n^ Case 4: clause C
containsj l^ ≥^ 4 terms.
Claim. CNF-SAT instance is satisfiableif and only if 3-CNF-SAT instance is.Proof.^ ⇒
Suppose SAT instance is satisfiable. n If SAT assignment sets t
= 1, 3-SAT assignment sets:jk
-^ t^ = 1jk^ –^ y= 1 for all m < k; ym^
= 0 for all mm^
≥^ k
ll l l l
ww w w v
jj
j
j j
j j
j j
j j
j j j jj jj j
tt y C
yt y C
yt y C
yt y C
yt y C
yt t C tt tt C
−^1 ’
(^55) 4 ’^5
(^44) 3 ’^4
(^33) 2 ’^3
(^22) 1 ’^2
(^11) 1 ’^1 (^32) SAT Reduces to 3-SAT 1 k = 4
set TRUE
n^ Case 2: clause C
containsj l^ ≥^ 4 terms.
Claim. CNF-SAT instance is satisfiableif and only if 3-CNF-SAT instance is.Proof.^ ⇐ Suppose 3-SAT instance is satisfiable. n If 3-SAT assignment sets t
= 1, SAT assignment sets tjk
= 1.jk
n^ Consider clause C
. We claim tj^
= 1 for some k.jk^
-^ each of l^ - 1 new Boolean variables y
can only make one ofj
l
new clauses true – the remaining clause must be satisfied by an original term t
jk
SAT Reduces to 3-SAT
ll l l l
ww w w v
jj
j
j j
j j
j j
j j
j j j jj jj j
tt y C
yt y C
yt y C
yt y C
yt y C
yt t C tt tt C
−^1 ’
(^55) 4 ’^5
(^44) 3 ’^4
(^33) 2 ’^3
(^22) 1 ’^2
(^11) 1 ’^1 (^32) 1
27
Polynomial-Time Reduction Basic strategies.^ n^ Reduction by simple equivalence.^ n^ Reduction from special case to general case.^ n^ Reduction from general case to special case.^ n^ Reduction by encoding with gadgets.
Clique
CLIQUE: Given N people and their pairwise relationships. Is there agroup of C people such that every pair in the group knows each other.Ex.^ n^ People: a, b, c, d, e,... , k.^ n^ Friendships: (a, e), (a, f), (a, g),.. ., (h, k).^ n^ Clique size: C = 4.
ba c h g
d e f
k j i Friendship Graph
b h
d
i
YES Instance
Docsity.com
29
Satisfiability Reduces to Clique Claim. CNF-SAT
n^ Given instance of CNF-SAT, create a person for each literal in eachclause. (x’ + y + z) (x + y’ + z) (y + z) (x’ + y’ + z’)C = 4 clauses
first clauseyx’^
z y^ z
x y’ z
x’ y’ z’
Satisfiability Reduces to Clique Claim. CNF-SAT
n^ Given instance of CNF-SAT, create a person for each literal in eachclause. n^ Two people know each other except if:^ –^ they come from the same clause^ –^ they represent a literal and its negation
yx’ z y z
x y’ z
x’ y’ z’
(x’ + y + z) (x + y’ + z) (y + z) (x’ + y’ + z’)
C = 4 clauses 31
Satisfiability Reduces to Clique Claim. CNF-SAT
n^ Given instance of CNF-SAT, create a person for each literal in eachclause. n^ Two people know each other except if:^ –^ they come from the same clause^ –^ they represent a literal and its negation n^ Clique of size C
⇒^ satisfiable assignment.
-^ set variable in clique to true –^ (x, y, z) = (true, true, false)
yx’ z y z
x y’ z
x’ y’ z’
(x’ + y + z) (x + y’ + z) (y + z) (x’ + y’ + z’)
C = 4 clauses
Satisfiability Reduces to Clique Claim. CNF-SAT
n^ Given instance of CNF-SAT, create a person for each literal in eachclause. n^ Two people know each other except if:^ –^ they come from the same clause^ –^ they represent a literal and its negation n^ Clique of size C
⇒^ satisfiable assignment. n^ Satisfiable assignment
⇒^ clique of size C.
-^ (x, y, z) = (true, true, false) –^ choose one true literal from eachclause
yx’ z y z
x y’ z
x’ y’ z’
(x’ + y + z) (x + y’ + z) (y + z) (x’ + y’ + z’)
C = 4 clauses
Docsity.com
37
Finding a Hamiltonian Cycle HAM-CYCLE: given an undirected graph G = (V, E), does there exist asimple cycle C that contains every vertex in V.FIND-HAM-CYCLE: given an undirected graph G = (V, E), output aHamiltonian cycle if one exists, otherwise output any cycle.Claim. HAM-CYLCE
Proof.^ ≤^
P
HAM-CYCLE (G) C ← FIND-HAM-CYCLE(G)IF (C is Hamiltonian)RETURN TRUEELSERETURN FALSE
Finding a Hamiltonian Cycle HAM-CYCLE: given an undirected graph G = (V, E), does there exist asimple cycle C that contains every vertex in V.FIND-HAM-CYCLE: given an undirected graph G = (V, E), output aHamiltonian cycle if one exists, otherwise output any cycle.Claim. HAM-CYLCE
Proof.^ ≥^
P
IF (HAM-CYCLE(G) = FALSE)RETURN FALSEA^ ←^ E FOR EACH e
IF (HAM-CYCLE(V, A - {e}) = TRUE)A^ ←^
A - {e} RETURN unique cycle remaining in G
39
Directed Hamiltonian Cycle DIR-HAM-CYCLE: given a directed graph G = (V, E), does there existsa simple directed cycle C that contains every vertex in V.Claim. DIR-HAM-CYCLE
Proof.^ n^ Given a directed graph G = (V, E), construct an undirected graph G’with 3n vertices.
v a b c
d e
vin aout b^ out cout
d^ in ein
v^ v G’ out
Directed Hamiltonian Cycle Claim. G has a Hamiltonian cycle if and only if G’ does.Proof.^ ⇒^ n^ Suppose G has a directed Hamiltonian cycle C.^ n^ Then G’ has an undirected Hamiltonian cycle.Proof.^ ⇐^ n^ Suppose G’ has an undirected Hamiltonian cycle C’.^ n^ C’ must visit nodes in G’ using one of following two orders:... , G, R, B, G, R, B, G, R, B,.. .... , R, G, B, R, G, B, R, G, B,...^ n^ Blue nodes in C’ make up directed Hamiltonian cycle C in G, orreverse of one.
Docsity.com
41
3-SAT Reduces to Directed Hamiltonian CycleClaim. 3-CNF-SAT
n^ Why not reduce from some other problem?^3
Need to find another problem that is sufficiently close.(could reduce from VERTEX-COVER) 3 If don’t succeed, start from 3-CNF-SAT since itscombinatorial structure is very basic. 3 Downside: reduction will require certain level ofcomplexity.
3-SAT Reduces to Directed Hamiltonian CycleProof: Given 3-CNF-SAT instance with n variables x
and k clauses Ci
.j
n^ Construct G to have 2
n^ Hamiltonian cycles. n^ Intuition: traverse path i from left to right
⇔^ set variable x
= 1.i
s t
n
3k + 3
43
3-SAT Reduces to Directed Hamiltonian CycleProof: Given 3-CNF-SAT instance with n variables x
and k clauses Ci
.j
n^ Add node and 6 edges for each clause.
s t
(^32) VV (^11) xx xC =
x^1 x^2 x^3
3-SAT Reduces to Directed Hamiltonian CycleProof: Given 3-CNF-SAT instance with n variables x
and k clauses Ci
.j
n^ Add node and 6 edges for each clause.
s t
(^32) VV (^12) xx xC =
x^1 x^2 x^3 Docsity.com
49
Implications Reduction
Proof that a problem is as hard as CNF-SAT is usually taken as signalto abandon hope of finding an efficient algorithm.
Implications Reduction
Proof that a problem is as hard as CNF-SAT is usually taken as signalto abandon hope of finding an efficient algorithm. 51
Problem Genres Basic genres.^ n^ Packing problems: SET-PACKING, INDEPENDENT SET.^ n^ Covering problems: SET-COVER, VERTEX-COVER.^ n^ Constraint satisfaction problems: SAT, 3-SAT.^ n^ Sequencing problems: HAMILTONIAN-CYCLE, TSP.^ n^ Partitioning problems: 3-COLOR.^ n^ Numerical problems: SUBSET-SUM, KNAPSACK, FACTOR.
3-Colorability 3-COLOR: Given an undirected graph does there exists a way to colorthe nodes R, G, and B such no adjacent nodes have the same color?
YES instanceDocsity.com
53
3-Colorability
Claim. 3-CNF-SAT
Proof: Given 3-SAT instance with n variables x
and k clauses Ci
.j
n^ Create instance of 3-COLOR G = (V, E) as follows. n^ Step 1:^ –^ create triangle R (false), G (true), or B^ –^ create nodes for each literal and connect to B^3
Each literal colored R or G. – create nodes for each literal, and connect literal to its negation 3 Each literal colored opposite of its negation.
T B
F
x^ x^11
x^ x^22
x^ xnn xx 33
Step 1
3-Colorability
Claim. 3-CNF-SAT
Proof: Given 3-SAT instance with n variables x
and k clauses Ci
.j
n^ Step 2:^ –^ for each clause, add "gadget" of 6 new nodes and 13 new edges
(^32) VV (^11) xx xC =^ Step 2
T
x^1
x^2
x^3
F
B
55
3-Colorability Claim. 3-CNF-SAT
Proof: Given 3-SAT instance with n variables x
and k clauses Ci
.j
n^ Step 2:^ –^ for each clause, add "gadget" of 6 new nodes and 13 new edges^ –^ if 3-colorable, top row must have at least one green (true) node^3
Otherwise, middle row all blue. 3 Bottom row alternates between green and red
contradiction.
(^32) VV (^11) xx xC =^ Step 2
T
x^1
x^2
x^3
F
x^1
x^2
x^3 B
3-Colorability Claim. 3-CNF-SAT
Proof: Given 3-SAT instance with n variables x
and k clauses Ci
.j
n^ Step 2:^ –^ for each clause, add "gadget" of 6 new nodes and 13 new edges^ –^ if top row has green (true) node, then 3-colorable^3
Color vertex below green node red, and one below that blue. 3 Color remaining middle row nodes blue. 3 Color remaining bottom nodes red or green, as forced.
(^32) VV (^11) xx xC =^ Step 2
T
x^1
x^2
x^3
F x^3 B
Docsity.com
61
Planar 3-Colorability
Claim. 3-COLOR
Proof sketch: Given instance of 3-COLOR, draw graph in plane,letting edges cross if necessary.^ n^ Replace each edge crossing with the following planar gadget W.^ –^ in any 3-coloring of W, opposite corners have the same color^ –^ any assignment of colors to the corners in which oppositecorners have the same color extends to a 3-coloring of W
Planar 4-Colorability
PLANAR-4-COLOR: Given a planar map, can it be colored using 4colors so that no adjacent regions have the same color?Intuition.^ n^ If PLANAR-3-COLOR is hard, then so is PLANAR-4-COLOR andPLANAR-5-COLOR.^ n^ Don’t always believe your intuition! 63
Planar 4-Colorability PLANAR-2-COLOR.^ n^ Solvable in linear time.PLANAR-3-COLOR.^ n^ NP-complete.PLANAR-4-COLOR.^ n^ Solvable in O(1) time.Theorem (Appel-Haken, 1976). Every planar map is 4-colorable.^ n^ Resolved century-old open problem.^ n^ Used 50 days of computer time to deal with many special cases.^ n^ First major theorem to be proved using computer.
Problem Genres Basic genres.^ n^ Packing problems: SET-PACKING, INDEPENDENT SET.^ n^ Covering problems: SET-COVER, VERTEX-COVER.^ n^ Constraint satisfaction problems: SAT, 3-SAT.^ n^ Sequencing problems: HAMILTONIAN-CYCLE, TSP.^ n^ Partitioning problems: 3D-MATCHING.^ n^ Numerical problems: SUBSET-SUM, KNAPSACK, FACTOR.
Docsity.com
65
Subset Sum
SUBSET-SUM: Given a set X of integers and a target integer t, is therea subset S
⊆^ X whose elements sum to exactly t. Example: X = {1, 4, 16, 64, 256, 1040, 1041, 1093, 1284, 1344}, t = 3754.^ n^ YES: S = {1, 16, 64, 256, 1040, 1093, 1284}.Remark.^ n^ With arithmetic problems, input integers are encoded in binary.^ n^ Polynomial reduction must be polynomial in binary encoding.
Subset Sum
Claim. VERTEX-COVER
Proof. Given instance G, k of VERTEX-COVER, create followinginstance of SUBSET-SUM.
1 4 5
2 ee^523 e 4 ee^131
e^3 1 eee^4 5 ee^1 2 v 1 0
(^0 1) v 2 0
(^0 0) v 3 1
(^0 0) v 4 0
e^61 1 v (^5) Node-arc incidence matrix
e^3 1 eee^4 5 ee^1 2 x 1 0
(^0 1) x 2 0
(^0 0) x 3 1
(^0 0) x 4 0
(^11111 1) x 15 0
(^1 0) y 1 0
(^0 1) y 2 1
(^0 0) y 3 0
(^0 0) y 4 0
(^0 0) y 5 0
(^000000 0) y (^06)
decimal5,1844,3564,1164,1615,3931,024^256641641 Treat as base k+1 integer
k = 3
(^2 2) t 3
k
67
Subset Sum
Claim. G has vertex cover of size k if and only if there is a subset Sthat sums to exactly t.Proof.^ ⇒^ n^ Suppose G has a vertex cover Cof size k.^ n^ Let S = C
∪^ { y: |ej^
-^ most significant bits add upto k –^ remaining bits add up to 2^14
(^25) e^53 e 4 ee^21 e^3 e^6
e^3 1 eee^4 5 ee^1 2 x 1 0
(^0 1) x 2 0
(^0 0) x 3 1
(^0 0) x 4 0
(^1 1) x 5 0
(^1 0) y 1 0
(^0 1) y 2 1
(^0 0) y 3 0
(^0 0) y 4 0
(^0 0) y 5 0
(^11111000000 0) y 06 2
(^2 2) t 3
decimal5,1844,3564,1164,1615,3931,024^256641641 15, k^
Subset Sum
Claim. G has vertex cover of size k if and only if there is a subset Sthat sums to exactly t.Proof.^ ⇐^ n^ Suppose subset S sums to t.^ n^ Let C = S
}.n
-^ each edge has three 1’s, sono carries possible –^ |C| = k –^ at least one x
musti contribute to sum for e
j 1 4 5
2 ee^523 e 4 ee^13 e 6
e^3 1 eee^4 5 ee^1 2 x 1 0
(^0 1) x 2 0
(^0 0) x 3 1
(^0 0) x 4 0
(^1 1) x 5 0
(^1 0) y 1 0
(^0 1) y 2 1
(^0 0) y 3 0
(^0 0) y 4 0
(^0 0) y 5 0
(^11111000000 0) y 06 2
(^2 2) t 3
decimal5,1844,3564,1164,1615,3931,024^256641641 15, k
Docsity.com