Algorithms and Theory of Computation Lecture 20: Reduction, SAT - - PowerPoint PPT Presentation

algorithms and theory of computation lecture 20 reduction
SMART_READER_LITE
LIVE PREVIEW

Algorithms and Theory of Computation Lecture 20: Reduction, SAT - - PowerPoint PPT Presentation

Algorithms and Theory of Computation Lecture 20: Reduction, SAT Xiaohui Bei MAS 714 October 27, 2020 Nanyang Technological University MAS 714 October 27, 2020 1 / 28 Recap P: set of decision problems that have polynomial time algorithms.


slide-1
SLIDE 1

Algorithms and Theory of Computation Lecture 20: Reduction, SAT

Xiaohui Bei MAS 714 October 27, 2020

Nanyang Technological University MAS 714 October 27, 2020 1 / 28

slide-2
SLIDE 2

Recap

P: set of decision problems that have polynomial time algorithms. NP: set of decision problems that have polynomial time nondeterministic algorithms.

Big Question

Does every problem in NP have an efficient algorithm? Same as asking whether P = NP. We don’t know the answer and many people believe that P = NP.

Nanyang Technological University MAS 714 October 27, 2020 2 / 28

slide-3
SLIDE 3

Reductions

A reduction from Problem X to Problem Y means (informally) that if we have an algorithm for Problem Y, we can use it to find an algorithm for Problem X. We use reductions to find algorithms to solve problems. show that we can’t find algorithms for some problems. (We say that these problems are hard.)

Nanyang Technological University MAS 714 October 27, 2020 3 / 28

slide-4
SLIDE 4

Reductions for Decision Problems/Languages

Reductions for Languages

For languages LX, LY, a reduction from LX to LY is an algorithm with input w ∈ Σ∗

  • utput w′ ∈ Σ∗

such that w′ ∈ LY ⇐ ⇒ w ∈ LX

(Actually, this is only one type of reduction, but this is the one we’ll use most often.) There are other kinds of reductions.

Nanyang Technological University MAS 714 October 27, 2020 4 / 28

slide-5
SLIDE 5

Reductions for Decision Problems/Languages

Reductions for Decision Problems

For decision problems X, Y, a reduction from X to Y is an algorithm with input: IX, an instance of X

  • utput: IY. an instance of Y

such that IY is YES instance of Y ⇐ ⇒ IX is YES instance of X

Nanyang Technological University MAS 714 October 27, 2020 5 / 28

slide-6
SLIDE 6

Using Reductions to Solve Problems

R: Reduction X → Y AY: algorithm for Y New algorithm for X: Algorithm: AX(IX): IY = R(IX); return AY(IY) If R and AY polynomial time = ⇒ AX polynomial time

Nanyang Technological University MAS 714 October 27, 2020 6 / 28

slide-7
SLIDE 7

Comparing Problems

If Problem X reduces to Problem Y (we write X ≤ Y), then “Problem X is no harder to solve than Problem Y”. X ≤ Y: X is no harder than Y, or Y is at least as hard as X.

Nanyang Technological University MAS 714 October 27, 2020 7 / 28

slide-8
SLIDE 8

Example of Reductions

Given a graph G, a set of vertices S is: independent set: no two vertices of S connected by an edge. clique: every pair of vertices in S is connected by an edge of G.

Nanyang Technological University MAS 714 October 27, 2020 8 / 28

slide-9
SLIDE 9

Independent Set and Clique Problems

Independent Set

Instance: A graph G and an integer k. Question: Does G have an independent set of size ≥ k?

Clique

Instance: A graph G and an integer k. Question: Does G have an clique of size ≥ k?

Nanyang Technological University MAS 714 October 27, 2020 9 / 28

slide-10
SLIDE 10

Recall

For decision problems X, Y, a reduction from X to Y is an algorithm that takes IX, an instance of X as input and returns IY, an instance of Y as output such that the solution (Y/N) to IY is the same as the solution to IX.

Nanyang Technological University MAS 714 October 27, 2020 10 / 28

slide-11
SLIDE 11

Reducing Independent Set to Clique

An instance of Independent Set is a graph G and an integer k. Reduction given G, k outputs G, k, where G is the complement of G, G has an edge (u, v) if and only if (u, v) is not an edge of G.

Nanyang Technological University MAS 714 October 27, 2020 11 / 28

slide-12
SLIDE 12

Correctness of Reduction

Lemma

G has an independent set of size at least k if and only if G has a clique of size at least k.

Proof.

Need to prove two facts: G has an independent set of size at least k implies that G has a clique of size at least k. G has a clique of size at least k implies that G has an independent set of size at least k. Easy to see both from the fact that S ⊆ V is an independent set in G if and only if S is a clique in G.

Nanyang Technological University MAS 714 October 27, 2020 12 / 28

slide-13
SLIDE 13

Independent Set and Clique

Independent Set ≤ Clique

◮ what does it mean?

If we have an algorithm for Clique, then we have an algorithm for Independent Set. Clique is at least as hard as Independent Set. Also... we can use a similar argument to prove that Independent Set is at least as hard as Clique.

Nanyang Technological University MAS 714 October 27, 2020 13 / 28

slide-14
SLIDE 14

Independent Set and Clique

Assume you can solve the Clique problem in time T(n), then you can solve the Independent Set problem in time (A) O(T(n)) (B) O(n log n + T(n)) (C) O(n2T(n2)) (D) O(n4T(n4)) (E) O(n2 + T(n2)) (F) We don’t care – all these are polynomial if T(n) is a polynomial, which is good enough for

  • ur purposes.

Nanyang Technological University MAS 714 October 27, 2020 14 / 28

slide-15
SLIDE 15

Polynomial Time Reductions

We say that an algorithm is efficient if it runs in polynomial-time. To find efficient algorithms for problems, we are only interested in polynomial-time

  • reductions. Reductions that take longer are not useful.

If we have a polynomial-time reduction from problem X to problem Y (we write X ≤P Y), and a poly-time algorithm AY for Y, we have a polynomial-time/efficient algorithm for X.

Nanyang Technological University MAS 714 October 27, 2020 15 / 28

slide-16
SLIDE 16

Polynomial Time Reductions

For decision problems X, Y, a polynomial reduction from X to Y is an algorithm A that has the following properties: A takes IX, an instance of X as input returns IY, an instance of Y as output runs in polynomial time such that the solution (Y/N) to IY is the same as the solution to IX.

Proposition

If X ≤P Y then a polynomial time algorithm for Y implies a polynomial time algorithm for X. Such a reduction is called a Karp reduction. Most reductions we will need are Karp reductions.

Nanyang Technological University MAS 714 October 27, 2020 16 / 28

slide-17
SLIDE 17

Transitivity of Reductions

Proposition

X ≤P Y and Y ≤P Z implies that X ≤P Z. Note: X ≤P Y does not imply that Y ≤P X and hence it is very important to know the FROM and TO in a reduction. To prove X ≤P Y you need to show a reduction FROM X TO Y That is, show that an algorithm for Y implies an algorithm for X.

Nanyang Technological University MAS 714 October 27, 2020 17 / 28

slide-18
SLIDE 18

Polynomial Time Reductions and Hardness

For decision problems X and Y, if X ≤P Y, and Y has an efficient algorithm, X has an efficient algorithm. If you believe that Independent Set does not have an efficient algorithm, why should you believe the same of Clique? Because we showed Independent Set ≤P Clique. If Clique had an efficient algorithm, so would Independent Set. If X ≤P Y and X does not have an efficient algorithm, Y cannot have an efficient algorithm!

Nanyang Technological University MAS 714 October 27, 2020 18 / 28

slide-19
SLIDE 19

The Satisfiability Problem (SAT)

Consider a set of boolean variables x1, x2, . . . , xn. A literal is either a boolean variable xi or its negation xi A clause is a disjunction of literals.

◮ e.g. x1 ∨ x2 ∨ x4 is a clause

A formula in conjunctive normal form (CNF) is propositional formula which is a conjunction of clauses.

◮ (x1 ∨ x2 ∨ x4) ∧ (x2 ∨ x3) ∧ x5 is a CNF formula

A formula ϕ is a 3CNF if every clause in ϕ has exactly 3 literals.

◮ (x1 ∨x2 ∨x4)∧(x2 ∨x3 ∨x1) is a 3CNF formula, but (x1 ∨x2 ∨x4)∧(x2 ∨x3)∧x5 is not. Nanyang Technological University MAS 714 October 27, 2020 19 / 28

slide-20
SLIDE 20

Satisfiability

SAT

Instance: A CNF formula ϕ Question: Is there a truth assignment to the variable of ϕ such that ϕ evaluates to true?

3SAT

Instance: A 3CNF formula ϕ Question: Is there a truth assignment to the variable of ϕ such that ϕ evaluates to true?

Example

1 (x1 ∨ x2 ∨ x4) ∧ (x2 ∨ x3) is satisfiable; take x1, . . . , x4 to be all true. 2 (x1 ∨ x2) ∧ (x1 ∨ x2) ∧ (x1 ∨ x2) ∧ (x1 ∨ x2) is not satisfiable. Nanyang Technological University MAS 714 October 27, 2020 20 / 28

slide-21
SLIDE 21

Importance of SAT and 3SAT

SAT and 3SAT are basic constraint satisfaction problems. Many different problems can reduced to them because of the simple yet powerful expressively of logical constraints. Arise naturally in many applications involving hardware and software verification and correctness. As we will see, it is a fundamental problem in theory of NP-Completeness.

Nanyang Technological University MAS 714 October 27, 2020 21 / 28

slide-22
SLIDE 22

SAT vs. 3SAT

Which problem is harder? It is easy to derive 3SAT ≤P SAT SAT is at least as hard as 3SAT But the reverse direction is also true.

Claim

SAT ≤P 3SAT Given ϕ as a SAT formula, we create a 3SAT formula ϕ′ such that ϕ is satisfiable iff ϕ′ is satisfiable ϕ′ can be constructed from ϕ in time polynomial in |ϕ|

Nanyang Technological University MAS 714 October 27, 2020 22 / 28

slide-23
SLIDE 23

SAT ≤P 3SAT

How SAT is different from 3SAT? In SAT clauses might have arbitrary length: 1, 2, 3, . . . variables. In 3SAT every clause must have exactly 3 different literals. To reduce from an instance of SAT to an instance of 3SAT, we must make all clauses to have exactly 3 literals. Basic Idea:

1 Pad short clauses so they have 3 literals. 2 Break long clauses into shorter clauses. 3 Repeat the above till we have a 3CNF. Nanyang Technological University MAS 714 October 27, 2020 23 / 28

slide-24
SLIDE 24

SAT ≤P 3SAT

A clause with < 3 literals

Clauses with two literals: Let c = ℓ1 ∨ ℓ2 be a clause with two literals. Let u be a new variable. Consider c′ =

  • ℓ1 ∨ ℓ2 ∨ u
  • ℓ1 ∨ ℓ2 ∨ u
  • bserve that c′ is satisfiable iff c is satisfiable

Clauses with one literal: Let c = ℓ be a clause with a single literal. Let u, v be new variables. Consider c′ =

  • ℓ ∨ u ∨ v
  • ℓ ∨ u ∨ v
  • ℓ ∨ u ∨ v
  • ℓ ∨ u ∨ v
  • again c′ is satisfiable iff c is satisfiable

Nanyang Technological University MAS 714 October 27, 2020 24 / 28

slide-25
SLIDE 25

Breaking a Clause

A clause with > 3 literals

Lemma

For any boolean formulas X and Y and z a new boolean variable. Then X ∨ Y is satisfiable if and only if, z can be assigned a value such that

  • X ∨ z
  • Y ∨ z
  • is satisfiable

(with the same assignment to the variables appearing in X and Y).

Nanyang Technological University MAS 714 October 27, 2020 25 / 28

slide-26
SLIDE 26

Breaking a Clause

A clause with > 3 literals

Let c = ℓ1 ∨ · · · ∨ ℓk. Let u1, . . . , uk−3 be new variables. Consider c′ =

  • ℓ1 ∨ ℓ2 ∨ u1
  • ℓ3 ∨ u1 ∨ u2
  • ℓ4 ∨ u2 ∨ u3
  • ∧ · · ·

  • ℓk−2 ∨ uk−4 ∨ uk−3
  • ℓk−1 ∨ ℓk ∨ uk−3
  • .

Claim

c is satisfiable if and only if c′ is satisfiable. Another way to see it – reduce size of clause by one: c′ =

  • ℓ1 ∨ ℓ2 ∨ . . . ∨ ℓk−2 ∨ uk−3
  • ℓk−1 ∨ ℓk ∨ uk−3
  • .

Nanyang Technological University MAS 714 October 27, 2020 26 / 28

slide-27
SLIDE 27

Overall Reduction Algorithm

Algorithm: ReduceSATTo3SAT(ϕ): foreach clause c of ϕ do if c does not have exactly 3 literals then construct c′ as described; else c′ = c; ϕ′ is the conjunction of all c′ constructed in loop; return ϕ′ Correctness (informal): ϕ is satisfiable iff ϕ′ is satisfiable because for each clause c, the new 3CNF formula c′ is logically equivalent to c. The reduction algorithm takes polynomial time.

Nanyang Technological University MAS 714 October 27, 2020 27 / 28

slide-28
SLIDE 28

2SAT

What about 2SAT? 2SAT can be solved in polynomial time! (specifically, linear time!) No known polynomial time reduction from SAT (or 3SAT) to 2SAT. If there was, then SAT and 3SAT would be solvable in polynomial time.

Nanyang Technological University MAS 714 October 27, 2020 28 / 28