Algorithm Design & Analysis: NP-Complete Problems & Approximation Algorithms (CS 410/584) , Study notes of Computer Science

A set of lecture notes from a university course on algorithm design & analysis (cs 410/584). The notes cover various topics related to np-complete problems, including the circuit satisfiability problem, its relationship to formula satisfiability and 3-sat, and the concept of reductions to prove other problems are np-complete. The document also introduces the concept of approximation algorithms for np-complete problems, specifically focusing on the vertex cover problem.

Typology: Study notes

Pre 2010

Uploaded on 08/18/2009

koofers-user-y6c
koofers-user-y6c 🇺🇸

10 documents

1 / 19

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 410/584, Algorithm Design & Analysis, Lecture Notes 10
1© 1994, 2003, 2003, 2006, 2008,
2009 David Maier
Algorithm Design & Analysis
Exhibiting an NP-Complete Problem
Need to show one
problem Q NP-complete
via a direct pr f
via a direct pr
oo
f
.
That is, show how to
reduce every other
problem in NP to it
(in )
Oth bl th
Q
David Maier 1
Lecture Notes 10
Oth
er
pro
bl
ems
can
th
en
be shown NP-hard by
reducing Q to them
Q1 Q2
NP
Algorithm Design & Analysis
Initial Problem
There are different initial problems in
the literature.
They are all based on encoding the
computation of polynomial-time
algorithms.
Rely on the “computational history” of
a poly-time algorithm is polynomial in
th i f th i t
David Maier 2
Lecture Notes 10
th
e
s
i
ze
o
f th
e
i
npu
t
.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download Algorithm Design & Analysis: NP-Complete Problems & Approximation Algorithms (CS 410/584) and more Study notes Computer Science in PDF only on Docsity!

2009 David Maier

Algorithm Design & Analysis

Exhibiting an NP-Complete Problem

Need to show one

problem Q NP-complete

via a direct prvia a direct proof. f

That is, show how to

reduce every other

problem in NP to it

(in )

Oth bl th

Q

Lecture Notes 10 David Maier (^1)

Other problems can then

be shown NP-hard by

reducing Q to them

Q1 Q

NP

Algorithm Design & Analysis

Initial Problem

There are different initial problems in

the literature.

They are all based on encoding the

computation of polynomial-time

algorithms.

Rely on the “computational history” of

a poly-time algorithm is polynomial in

th i f th i t

Lecture Notes 10 David Maier (^2)

the size of the input.

2009 David Maier

Algorithm Design & Analysis

Configurations of an Algorithm

Suppose A is a verification algorithm

with time complexity bounded by c⋅n k

  • On each step of the underlying machineO h t f th d l i hi model, it can write at most d bits
  • So A uses at most d⋅c⋅n k^ bits of memory in any computation with an input of length
  • If there are e bits of other state ( i ) h

Lecture Notes 10 David Maier (^3)

(registers, program counter), then one configuration of the machine needs

Algorithm Design & Analysis

All Configurations

If we represent the configuration at

each step in one computation, need

at most c⋅n k(e + d( ⋅c⋅n k) =)

There is a bit more. Have to have

  • input x, |x| =
  • certificate y |y|

Lecture Notes 10 David Maier (^4)

certificate y, |y|

  • instructions of A – size is

2009 David Maier

Algorithm Design & Analysis

Example

Is there a satisfying assignment for

this circuit?

B

A

Lecture Notes 10 David Maier (^7)

D

C

Algorithm Design & Analysis

Circuit Satisfiability is in NP

Assume an instance is represented as a

directed graph

  • edges as wiresd i
  • nodes are labeled with the kind of gate
  • number of inputs can grow linearly with representation: O( ) to enumerate inputs

Problem is in NP

Certificate = assignment of 0 or 1 N d t h k

Lecture Notes 10 David Maier (^8)

Need to check:

  • Each gate behaves appropriately given its input and output
  • output of whole circuit is

2009 David Maier

Algorithm Design & Analysis

Circuit Sat is NP-Hard

Given any problem Q in NP

Need a polynomial-time function f that maps a string x to a circuit C such that x is in Qa string x to a circuit C, such that x is in Q if and only if

Must have a verification algorithm

A(x, y) for Q with running time T(n)

in

using certificates bounded by S(n) in

Lecture Notes 10 David Maier (^9)

Algorithm Design & Analysis

Configurations of Computation of A

A configuration is essentially wires

A PC Aux state x y Memory

Initial configuration

Lecture Notes 10 David Maier (^10)

A PC Aux state x y Memory

2009 David Maier

Algorithm Design & Analysis

Formula Satisfiability

Input: Boolean formula using:

PlPl us parens and Boolean variablesd B l i bl

Is there an assignment of true, false to

the variables that makes the formulas

true

((x ∧ ¬y) ∨ z) ↔ (w → x)

Lecture Notes 10 David Maier (^13)

Algorithm Design & Analysis Reducing Circuit Sat to Formula Sat Might seem like we can just work backwards from the output of the circuit, and write down formula

B

A

B

D

C

Lecture Notes 10 David Maier (^14)

2009 David Maier

Algorithm Design & Analysis Instead, Variable per Wire, Sub-formula per Gate Plus, output wire is true

B

A w

w

w w7 w

D

C

w

w w

(w1 ↔ (A ∧ B)) (w2 ↔ (C ∧ D)) (w3 ↔ ¬w1) (w4 ↔ ¬w2)

w

Lecture Notes 10 David Maier (^15)

(w5 ↔ (w1 ∨ w2)) (w6 ↔ (w3 ∨ w4)) (w7 ↔ (w5 ∧ w6)) (w8↔ ¬w7) w

Algorithm Design & Analysis

Properties of Resulting Formula

1. Linear in the size of the circuit,

hence

2. Can be constructed from the

circuit in polynomial time

3. Is satisfiable if and only if the

original

Polynomial-time reduction from circuit

Lecture Notes 10 David Maier (^16)

y

sat to formula sat

So formula sat is NP-Hard Is formula sat in NP?

2009 David Maier

Algorithm Design & Analysis

Each Component Formula Has 3 Literals

Can convert each to 3-CNF

How? List cases that are false

(b2 ↔ (x ∧ b1)) F T T (¬b2 ∧ x ∧ b1) ∨ T F T (b2 ∧ ¬x ∧ b1) ∨ T T F (b2 ∧ x ∧ ¬b1) ∨ T F F (b2 ∧ ¬x ∧ ¬b1)

Then use DeMorgan’s Laws

Lecture Notes 10 David Maier (^19)

Then use DeMorgan s Laws

¬(x ∧ y) = ¬x ∨ ¬y ¬(x ∨ y) = ¬x ∧ ¬y

Algorithm Design & Analysis

Result is in 3-CNF

(b2 ∨ ¬x ∨ ¬b1) ∧ (¬b2 ∨ x ∨ ¬b1) ∧ ((¬¬b2b2 ∨ ¬∨ ¬xx ∨∨ b1)b1) ∧∧ (¬b2 ∨ x ∨ b1)

What about 2-literal clauses?

(x ∨ ¬z) Add a new variable p (x ∨ ¬z ∨ p) ∧ (x ∨ ¬z ∨ ¬p)

Wh t b t 1 lit l l?

Lecture Notes 10 David Maier (^20)

What about 1-literal clauses?

2009 David Maier

Algorithm Design & Analysis

Things to Check

  • Translation can be done in polynomial

time

  • 3-SAT is in NP

The 3-SAT problem is NP-complete

Lecture Notes 10 David Maier (^21)

Algorithm Design & Analysis

Branching Out from Logic

Graph problems

Clique of an undirected graph G = (N, E)q g p

Set of nodes M such that (m1, m2) in E for every

Does this graph have a clique of 4

A B C

Lecture Notes 10 David Maier (^22)

nodes? Does it have a clique of 5 nodes?

D E F

2009 David Maier

Algorithm Design & Analysis Equivalence

Suppose formula is satisfiable

Must make at least one literal true in each clause These literals must be compatible, so there are

So there must be a

Suppose there is a clique of size k

Must have exactly one node corresponding to each clause (why?) T ll hi h lit l t k t h

Lecture Notes 10 David Maier (^25)

Tells us which literals to make true, hence which variables to make true or false

Must be compatible literals

Algorithm Design & Analysis

How Big is This Graph?

Number of nodes =

Number of edges

So we can reduce 3-SAT to CLIQUE in

polynomial time

Lecture Notes 10 David Maier (^26)

Is CLIQUE in NP?

2009 David Maier

Algorithm Design & Analysis

Vertex Cover

Given an undirected graph G = (V, E)

and integer j, is there a set of j

n des P such that f r each ed enodes P such that for each edge

{v, w} in E,

Does this graph have a vertex cover

A B C

Lecture Notes 10 David Maier (^27)

of 2 nodes? Does it have a vertex cover of 1 node?

D E F

Algorithm Design & Analysis

Complement Graph

This last graph is the complement of

the example for clique

HHas exactly the missing edges tl th i i d

A B C

Lecture Notes 10 David Maier (^28)

D E F

2009 David Maier

Algorithm Design & Analysis

Examples

S = {3104, 11015, 22010, 117, 8506,

target t = 22324

Second example: same S

target t = 2324

Lecture Notes 10 David Maier (^31)

Algorithm Design & Analysis

Reduction from 3-SAT

Use decimal numbers, divide into

positions

  • Some for variables: Make sure
  • Some for clauses: Make sure each

has

Lecture Notes 10 David Maier (^32)

2009 David Maier

Algorithm Design & Analysis

Approximation Algorithms for NP-Complete Problems

If Q is NP-complete, then what can we

do?

  • Limit ourselves to small inputsLimit ourselves to small inputs
  • Find special cases that can be

solved in polynomial time

  • Find poly-time algorithms that give

good approximations

For example for 3 SAT is there a poly time

Lecture Notes 10 David Maier (^33)

For example, for 3-SAT, is there a poly-time algorithm that is guaranteed to find an assignment (if it exists) that

Algorithm Design & Analysis

Approximating Vertex Cover

If we could find the minimum size

vertex cover, M, for a graph G, we

c uld answer the questi n if G has acould answer the question if G has a

vertex cover of size k.

Will show a poly-time algorithm that

finds a cover C of G such that |C|

Lecture Notes 10 David Maier (^34)

2009 David Maier

Algorithm Design & Analysis

Approximation Bound

Why is C within a factor of two of

minimum M?

L t F bLet F be chosen edges. So C = h d S C

  1. No two edges in F have a node in common. Suppose it has {u, v} and {u, w}. Assume {u, v} chosen first. Then
  2. So, no cover can have a node x that covers

Lecture Notes 10 David Maier (^37)

  1. M must have at least one node for each edge in F, so |M| ≥ |F|, |C| =