Max Cut NP Complete
Max Cut NP Complete
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 399
A Cut of Size 4
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 400
min cut and max cut (concluded)
• max cut has applications in circuit layout.
– The minimum area of a VLSI layout of a graph is not
less than the square of its maximum cut size.a
a Raspaud, Sýkora, & Vrťo (1995); Mak & Wong (2000).
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 401
max cut Is NP-Completea
• We will reduce naesat to max cut.
• Given a 3sat formula φ with m clauses, we shall
construct a graph G = (V, E) and a goal K.
• Furthermore, there is a cut of size at least K if and only
if φ is nae-satisfiable.
• Our graph will have multiple edges between two nodes.
– Each such edge contributes one to the cut if its nodes
are separated.
a Karp
(1972); Garey, Johnson, & Stockmeyer (1976). max cut re-
mains NP-complete even for graphs with maximum degree 3 (Makedon,
Papadimitriou, & Sudborough, 1985).
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 402
The Proof
• Suppose φ’s m clauses are C1 , C2 , . . . , Cm .
• The boolean variables are x1 , x2 , . . . , xn .
• G has 2n nodes: x1 , x2 , . . . , xn , ¬x1 , ¬x2 , . . . , ¬xn .
• Each clause with 3 distinct literals makes a triangle in G.
• For each clause with two identical literals, there are two
parallel edges between the two distinct literals.
– Call it a degenerate triangle.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 403
[M
[L
»[ N
[L »[ M
[L »[ L
QL FRSLHV
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 404
The Proof (continued)
• Assume φ has no clauses with only one distinct literal
(why?).
• Ignore clauses containing two opposite literals xi and
¬xi (why?).
• For each variable xi , add ni copies of edge [ xi , ¬xi ],
where ni is the number of occurrences of xi and ¬xi in φ.
• Note that
n
ni = 3m.
i=1
– The summation counts the number of literals in φ.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 405
The Proof (continued)
• Set K = 5m.
• Suppose there is a cut (S, V − S) of size 5m or more.
• A clause (a triangle, i.e.) contributes at most 2 to a cut
however you split it.a
• Suppose some xi and ¬xi are on the same side of the
cut.
• They together contribute at most 2ni edges to the cut.
– They appear in at most ni different clauses.
– A clause contributes at most 2 to a cut.
a See p. 404.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 406
[L
3
L
QL Ø Ù
WULDQJOHV
»[ L
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 407
The Proof (continued)
• Either xi or ¬xi contributes at most ni to the cut by the
pigeonhole principle.
• Changing the side of that literal does not decrease the
size of the cut.
• Hence we assume variables are separated from their
negations.
• The total number of edges in the cut that join opposite
n
literals xi and ¬xi is i=1 ni .
n
• But we knew i=1 ni = 3m.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 408
The Proof (concluded)
• The remaining K − 3m ≥ 2m edges in the cut must
come from the m triangles that correspond to clauses.
• Each can contribute at most 2 to the cut.
• So all are split.
• A split clause means at least one of its literals is true
and at least one false.
• The other direction is left as an exercise.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 409
This Cut Does Not Meet the Goal K = 5 × 3 = 15
[ » [
[ » [
[ » [
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 410
This Cut Meets the Goal K = 5 × 3 = 15
[ » [
WUXH
» [ [
IDOVH
[ » [
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 411
Remarks
• We had proved that max cut is NP-complete for
multigraphs.
• How about proving the same thing for simple graphs?a
• How to modify the proof to reduce 4sat to max cut?b
• All NP-complete problems are mutually reducible by
definition.c
– So they are equally hard in this sense.d
a Contributed by Mr. Tai-Dai Chou (J93922005) on June 2, 2005.
b Contributed by Mr. Chien-Lin Chen (J94922015) on June 8, 2006.
c Contributed by Mr. Ren-Shuo Liu (D98922016) on October 27, 2009.
d Contributed by Mr. Ren-Shuo Liu (D98922016) on October 27, 2009.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 412
max bisection
• max cut becomes max bisection if we require that
| S | = | V − S |.
• It has many applications, especially in VLSI layout.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 413
max bisection Is NP-Complete
• We shall reduce the more general max cut to max
bisection.
• Add | V | = n isolated nodes to G to yield G .
• G has 2n nodes.
• G ’s goal K is identical to G’s
– As the new nodes have no edges, they contribute 0 to
the cut.
• This completes the reduction.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 414
The Proof (concluded)
• A cut (S, V − S) can be made into a bisection by
allocating the new nodes between S and V − S.
• Hence each cut of G can be made a cut of G of the
same size, and vice versa.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 415
bisection width
• bisection width is like max bisection except that it
asks if there is a bisection of size at most K (sort of min
bisection).
• Unlike min cut, bisection width is NP-complete.
• We reduce max bisection to bisection width.
• Given a graph G = (V, E), where | V | is even, we
generate the complementa of G.
• Given a goal of K, we generate a goal of n2 − K.b
a Recall p. 398.
b | V | = 2n.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 416
The Proof (concluded)
• To show the reduction works, simply notice the following
easily verifiable claims.
– A graph G = (V, E), where | V | = 2n, has a bisection
of size K if and only if the complement of G has a
bisection of size n2 − K.
– So G has a bisection of size ≥ K if and only if its
complement has a bisection of size ≤ n2 − K.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 417
hamiltonian path Is NP-Completea
Theorem 48 Given an undirected graph, the question
whether it has a Hamiltonian path is NP-complete.
a Karp (1972).
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 418
A Hamiltonian Path at IKEA, Covina, California?
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 419
Random hamiltonian cycle
• Consider a random graph where each pair of nodes are
connected by an edge independently with probability
1/2.
• Then it contains a Hamiltonian cycle with probability
1 − o(1).a
a Frieze & Reed (1998).
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 420
tsp (d) Is NP-Complete
Corollary 49 tsp (d) is NP-complete.
• We will reduce hamiltonian path to tsp (d).
• Consider a graph G with n nodes.
• Create a weighted complete graph G with the same
nodes as G.
• Set dij = 1 on G if [ i, j ] ∈ G and dij = 2 on G if
[ i, j ] ∈ G.
– Note that G is a complete graph.
• Set the budget B = n + 1.
• This completes the reduction.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 421
tsp (d) Is NP-Complete (continued)
• Suppose G has a toura of distance at most n + 1.
• Then that tour on G must contain at most one edge
with weight 2.
• If a tour on G contains one edge with weight 2, remove
that edge to arrive at a Hamiltonian path for G.
• Suppose a tour on G contains no edge with weight 2.
• Remove any edge to arrive at a Hamiltonian path for G.
aA tour is a cycle, not a path.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 422
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 423
tsp (d) Is NP-Complete (concluded)
• On the other hand, suppose G has a Hamiltonian path.
• There is a tour on G containing at most one edge with
weight 2.
– Start with a Hamiltonian path.
– Insert the edge connecting the beginning and ending
nodes to yield a tour.
• The total cost is then at most (n − 1) + 2 = n + 1 = B.
• We conclude that there is a tour of length B or less on
G if and only if G has a Hamiltonian path.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 424
Random tsp
• Suppose each distance dij is picked uniformly and
independently from the interval [ 0, 1 ].
• Then the total distance of the shortest tour has a mean
√
value of β n for some positive β.a
• In fact, the total distance of the shortest tour deviates
from the mean by more than t with probability at most
2
e−t /(4n) !b
a Beardwood, Halton, & Hammersley (1959).
b Rhee & Talagrand (1987); Dubhashi & Panconesi (2012).
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 425
Graph Coloring
• k-coloring: Can the nodes of a graph be colored with
≤ k colors such that no two adjacent nodes have the
same color?a
• 2-coloring is in P (why?).
• But 3-coloring is NP-complete (see next page).
• k-coloring is NP-complete for k ≥ 3 (why?).
• exact-k-coloring asks if the nodes of a graph can be
colored using exactly k colors.
• It remains NP-complete for k ≥ 3 (why?).
ak is not part of the input; k is part of the problem statement.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 426
3-coloring Is NP-Completea
• We will reduce naesat to 3-coloring.
• We are given a set of clauses C1 , C2 , . . . , Cm each with 3
literals.
• The boolean variables are x1 , x2 , . . . , xn .
• We now construct a graph that can be colored with
colors { 0, 1, 2 } if and only if all the clauses can be
nae-satisfied.
a Karp (1972).
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 427
The Proof (continued)
• Every variable xi is involved in a triangle [ a, xi , ¬xi ]
with a common node a.
• Each clause Ci = (ci1 ∨ ci2 ∨ ci3 ) is also represented by a
triangle
[ ci1 , ci2 , ci3 ].
– Node cij and a node in an a-triangle [ a, xk , ¬xk ]
with the same label represent distinct nodes.
• There is an edge between literal cij in the a-triangle and
the node representing the jth literal of Ci .a
a Alternativeproof: There is an edge between ¬cij and the node
that represents the jth literal of Ci . Contributed by Mr. Ren-Shuo Liu
(D98922016) on October 27, 2009.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 428
Construction for · · · ∧ (x1 ∨ ¬x2 ∨ ¬x3 ) ∧ · · ·
,
[ [ [
c [
[ c [
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 429
The Proof (continued)
Suppose the graph is 3-colorable.
• Assume without loss of generality that node a takes the
color 2.
• A triangle must use up all 3 colors.
• As a result, one of xi and ¬xi must take the color 0 and
the other 1.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 430
The Proof (continued)
• Treat 1 as true and 0 as false.a
– We are dealing with the a-triangles here, not the
clause triangles yet.
• The resulting truth assignment is clearly contradiction
free.
• As each clause triangle contains one color 1 and one
color 0, the clauses are nae-satisfied.
– Here, treat 0 as true and 1 as false.
– Ignore 2’s truth value as it is irrelevant now.
a The opposite also works.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 431
The Proof (continued)
Suppose the clauses are nae-satisfiable.
• For each a-triangle:
– Color node a with color 2.
– Color the nodes representing literals by their truth
values (color 0 for false and color 1 for true).
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 432
The Proof (continued)
• For each clause triangle:
– Pick any two literals with opposite truth values.a
– Color the corresponding nodes with 0 if the literal is
true and 1 if it is false.
– Color the remaining node with color 2 regardless of
its truth value.
a Break ties arbitrarily.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 433
The Proof (concluded)
• The coloring is legitimate.
– If literal w of a clause triangle has color 2, then its
color will never be an issue.
– If literal w of a clause triangle has color 1, then it
must be connected up to literal w with color 0.
– If literal w of a clause triangle has color 0, then it
must be connected up to literal w with color 1.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 434
More on 3-coloring and the Chromatic Number
• 3-coloring remains NP-complete for planar graphs.a
• Assume G is 3-colorable.
• There is a classic algorithm that finds a 3-coloring in
time O(3n/3 ) = 1.4422n .b
• It can be improved to O(1.3289n ).c
a Garey, Johnson, & Stockmeyer (1976); Dailey (1980).
b Lawler (1976).
c Beigel & Eppstein (2000).
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 435
More on 3-coloring and the Chromatic Number
(concluded)
• The chromatic number χ(G) is the smallest number
of colors needed to color a graph G.
• There is an algorithm to find χ(G) in time
O((4/3)n/3 ) = 2.4422n .a
• It can be improved to O((4/3 + 34/3 /4)n ) = O(2.4150n )b
and 2n nO(1) .c
• Computing χ(G) cannot be easier than 3-coloring.d
a Lawler (1976).
b Eppstein (2003).
c Koivisto (2006).
d Contributed by Mr. Ching-Hua Yu (D00921025) on October 30, 2012.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 436
tripartite matchinga (3dm)
• We are given three sets B, G, and H, each containing n
elements.
• Let T ⊆ B × G × H be a ternary relation.
• tripartite matching asks if there is a set of n triples
in T , none of which has a component in common.
– Each element in B is matched to a different element
in G and different element in H.
Theorem 50 (Karp, 1972) tripartite matching is
NP-complete.
a Princess
Diana (November 20, 1995), “There were three of us in this
marriage, so it was a bit crowded.”
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 437
Related Problems
• We are given a family F = { S1 , S2 , . . . , Sn } of subsets
of a finite set U and a budget B.
• set covering asks if there exists a set of B sets in F
whose union is U .
• set packing asks if there are B disjoint sets in F .
• exact cover asks if there are disjoint sets in F whose
union is U .
• Assume | U | = 3m for some m ∈ N and | Si | = 3 for all i.
• exact cover by 3-sets (x3c) asks if there are m sets
in F that are disjoint (so have U as their union).
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 438
SET COVERING SET PACKING
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 439
Related Problems (concluded)
Corollary 51 (Karp, 1972) set covering, set
packing, exact cover, and x3c are all NP-complete.
• Does set covering remain NP-complete when
| Si | = 3?a
• set covering is used to prove that the influence
maximization problem in social networks is
NP-complete.b
by Mr. Kai-Yuan Hou (B99201038, R03922014) on
a Contributed
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 440
knapsack
• There is a set of n items.
• Item i has value vi ∈ Z+ and weight wi ∈ Z+ .
• We are given K ∈ Z+ and W ∈ Z+ .
• knapsack asks if there exists a subset
I ⊆ { 1, 2, . . . , n }
such that i∈I wi ≤ W and i∈I vi ≥ K.
– We want to achieve the maximum satisfaction within
the budget.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 441
knapsack Is NP-Completea
• knapsack ∈ NP: Guess an I and check the constraints.
• We shall reduce x3cb to knapsack, in which vi = wi
for all i and K = W .
• The simplified knapsack now asks if a subset of
v1 , v2 , . . . , vn adds up to exactly K.c
– Picture yourself as a radio DJ.
a Karp (1972). It can be solved in time O(2n/2 ) with space O(2n/4 )
(Schroeppel & Shamir, 1981; Vyskoč, 1987).
b exact cover by 3-sets.
c This important problem is called subset sum or 0-1 knapsack. The
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 442
The Proof (continued)
• The primary differences between the two problems are:a
– Sets vs. numbers.
– Union vs. addition.
• We are given a family F = { S1 , S2 , . . . , Sn } of size-3
subsets of U = { 1, 2, . . . , 3m }.
• x3c asks if there are m sets in F that cover the set U .
– These m subsets are disjoint by necessity.
a Thanks to a lively class discussion on November 16, 2010.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 443
The Proof (continued)
• Think of a set as a bit vectora in { 0, 1 }3m .
– Assume m = 3.
– 110010000 means the set { 1, 2, 5 }.
– 001100010 means the set { 3, 4, 8 }.
• Our goal is
3m
11···1.
a Also called characteristic vector.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 444
The Proof (continued)
• A bit vector can also be seen as a binary number.
• Set union resembles addition:
001100010
+ 110010000
111110010
which denotes the set { 1, 2, 3, 4, 5, 8 }, as desired.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 445
The Proof (continued)
• Trouble occurs when there is carry:
010000000
+ 010000000
100000000
• This denotes the wrong set { 1 }, not the correct set { 2 }.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 446
The Proof (continued)
• Or consider
001100010
+ 001110000
011010010
• This denotes the wrong set { 2, 3, 5, 8 }, not the correct
set { 3, 4, 5, 8 }.a
a Corrected by Mr. Chihwei Lin (D97922003) on January 21, 2010.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 447
The Proof (continued)
• Carry may also lead to a situation where we obtain our
3m
solution 1 1 · · · 1 with more than m sets in F .
• For example, with m = 3,
000100010
001110000
101100000
+ 000001101
111111111
• But the correct union result, { 1, 3, 4, 5, 6, 7, 8, 9 }, is not
an exact cover.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 448
The Proof (continued)
• And it uses 4 sets instead of the required m = 3.a
• To fix this problem, we enlarge the base just enough so
that there are no carries.b
• Because there are n vectors in total, we change the base
from 2 to n + 1.
• Every positive integer N has a unique expression in base
b: There are b-adic digits 0 ≤ di < b such that
k
N= d i bi , dk = 0.
i=0
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 449
The Proof (continued)
• Set vi to be the integer corresponding to the bit vectora
encoding Si :
Δ
vi = 1 × (n + 1)3m−j (base n + 1). (4)
j∈Si
• Set
3m
3m−1
Δ j
K= 1 × (n + 1) = 1 1 · · · 1 (base n + 1).
j=0
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 450
The Proof (continued)
• Suppose there is a set I such that
3m
vi = 1 1 · · · 1 (base n + 1).
i∈I
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 451
The Proof (continued)
• For example, the case on p. 448 becomes
000100010
001110000
101100000
+ 000001101
102311111
in base n + 1 = 6.
• As desired, it no longer meets the goal.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 452
The Proof (continued)
• Suppose F admits an exact cover, say { S1 , S2 , . . . , Sm }.
• Then picking I = { 1, 2, . . . , m } clearly results in
3m
v1 + v2 + · · · + vm = 11···1.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 453
The Proof (concluded)
• On the other hand, suppose there exists an I such that
3m
vi = 1 1 · · · 1
i∈I
in base n + 1.
• The no-carry property implies that | I | = m and
{ Si : i ∈ I }
is an exact cover.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 454
subset suma Is NP-Complete
• The proof actually proves:
Corollary 52 subset sum is NP-complete.
• The proof can be slightly revised to reduce exact
cover to subset sum.
• The proof would not work if you used m + 1 as the
base.b
a Recall
p. 442.
b Contributed by Mr. Yuchen Wang (R08922157) on November 19,
2020.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 455
An Example
• Let m = 3, U = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, and
S1 = { 1, 3, 4 },
S2 = { 2, 3, 4 },
S3 = { 2, 5, 6 },
S4 = { 6, 7, 8 },
S5 = { 7, 8, 9 }.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 456
An Example (continued)
• Our reduction produces
3×3
3×3−1
j
K = 6 = 1 1 · · · 16 = 201553910 ,
j=0
v1 = 1011000006 = 173404810 ,
v2 = 0111000006 = 33436810 ,
v3 = 0100110006 = 28144810 ,
v4 = 0000011106 = 25810 ,
v5 = 0000001116 = 4310 .
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 457
An Example (concluded)
• Note v1 + v3 + v5 = K because
101100000
010011000
+ 000000111
111111111
• Indeed,
S1 ∪ S3 ∪ S5 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 },
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 458
bin packing
• We are given N positive integers a1 , a2 , . . . , aN , an
integer C (the capacity), and an integer B (the number
of bins).
• bin packing asks if these numbers can be partitioned
into B subsets, each of which has total sum at most C.
• Think of packing bags at the check-out counter.
Theorem 53 bin packing is NP-complete.
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 459
bin packing (concluded)
• But suppose a1 , a2 , . . . , aN are randomly distributed
between 0 and 1.
• Let B be the smallest number of unit-capacity bins
capable of holding them.
• Then B can deviate from its average by more than t
2
with probability at most 2e−2t /N .a
a Rhee & Talagrand (1987); Dubhashi & Panconesi (2012).
c
2021 Prof. Yuh-Dauh Lyuu, National Taiwan University Page 460