• 沒有找到結果。

Slides credited from Hsueh-I Lu & Hsu-Chun Hsiao

N/A
N/A
Protected

Academic year: 2022

Share "Slides credited from Hsueh-I Lu & Hsu-Chun Hsiao"

Copied!
63
0
0

加載中.... (立即查看全文)

全文

(1)

Slides credited from Hsueh-I Lu & Hsu-Chun Hsiao

(2)

Homework 4 released

Due on 1/3 (Thur) 14:20 (three weeks later)

Mini-HW 10 released

Due on 12/20 (Thur) 14:20

Next week

Break

Watch online videos

Class 12/27

A small test for Christmas (optional)

2

(3)
(4)

 Complexity Classes

 P v.s. NP

 NP, NP-Complete, NP-Hard

 Polynomial-Time Reduction

4

(5)

Input: a graph G

Output: a smallest vertex subset of G that covers all edges of G.

Known to be NP-complete

(6)

6

(7)

Input: a Graph G and an integer k.

Output: Does G contain a vertex cover of size no more than k?

Original problem  optimization problem

原先的路燈問題是要算出放路燈的方法

Yes/No  decision problem

問k盞路燈夠不夠照亮整個公園

(8)

8

Non-Deterministic-Vertex-Cover(G, k) set S = {}

for each vertex x of G

non-deterministically insert x to S if |S| > k

output no

if S is not a vertex cover output no

output yes

(9)

If the correct answer is yes, then there is a computation path of the algorithm that leads to yes.

至少有一條路是對的

If the correct answer is no, then all computation paths of the algorithm lead to no.

每一條路都是對的

Non-Deterministic-Vertex-Cover(G, k) set S = {}

for each vertex x of G

non-deterministically insert x to S if |S| > k

output no

if S is not a vertex cover output no

output yes

(10)

10

initial configuration

correct answer

(11)

polynomial

“solved” in non-deterministic polynomial time

= “verified” in polynomial time

(12)

P ⊆ NP

A problem solvable in polynomial time is verifiable in polynomial time as well

Any NP problem can be solved in (deterministically) exponential time?

Yes

Any NP problem can be solved in (deterministically) polynomial time?

Open problem

12

Why?

(13)

http://www.claymath.org/millennium-problems

(14)

Yang–Mills and Mass Gap

Riemann Hypothesis

P vs NP Problem

Navier–Stokes Equation

Hodge Conjecture

Poincaré Conjecture (solved by Grigori Perelman)

Birch and Swinnerton-Dyer Conjecture

14

Grigori Perelman

Fields Medal (2006), declined Millennium Prize (2010), declined

(15)

Aug 2010 claimed a proof of P is

not equal to NP.

(16)

problems that are verifiable  solvable

public-key cryptography will be broken

16

Widespread belief in P ≠ NP

“If P = NP, then the world would be a profoundly different place than we usually assume it to be. There would be no special value in “creative leaps,” no fundamental gap between solving a problem and recognizing the solution once it's found. Everyone who could appreciate a symphony would be Mozart; everyone who could follow a step-by-step argument would be Gauss...” – Scott Aaronson, MIT

(17)

Travelling Salesman (2012)

A movie about P = NP

Best Feature Film in Silicon Valley Film Festival 2012

(18)

18

(19)

A problem is NP-hard if it is as least as hard as all NP problems.

In other words, a problem X is NP-hard if the following condition holds:

If X can be solved in (deterministic) polynomial time, then all NP problems can be solved in (deterministic) polynomial time.

(20)

20

A problem is NP-complete if

it is NP-hard and

it is in NP.

In other words, an NP-complete problem is one of the “hardest”

problems in the class NP.

In other words, an NP-complete problem is a hardness representative problem of the class NP.

Hardest in NP  solving one NPC can solve all NP problems (“complete”)

It is wildly believed that NPC problems have no polynomial-time solution

 good reference point to judge whether a problem is in P

We can decide whether a problem is “too hard to solve” by showing it is as hard as an NPC problem

We then focus on designing approximate algorithms or solving special cases

(21)

Class P: class of problems that can be solved in

Class NP: class of problems that can be verified in

Class NP-hard: class of problems that are “at least as hard as all NP problems”

Class NP-complete: class of problems in both NP and NP-hard

P ≠ NP P = NP 21

(22)

22

undecidable: no algorithm;

e.g. halting problem

https://www.youtube.com/watch?v=wGLQiHXHWNk

(23)

Halting problem is to determine whether a program 𝑝 halts on input 𝑥

Proof for undecidable via a counterexample

Suppose ℎ can determine whether a program 𝑝 halts on input 𝑥

ℎ(𝑝, 𝑥) = return (p halts on input x)

Define g(p) = if h(p,p) is 0 then return 0 else HANG

 g(g) = if h(g,g) is 0 then return 0 else HANG

Both cases contradict the assumption:

1. g halts on g: then h(g,g)=1, which would make g(g) hang

2. g does not halt on g: then h(g,g)=0, which would make g(g) halt

(24)

Which one is in P?

24

Shortest Simple Path Longest Simple Path

Euler Tour Hamitonian Cycle

LCS with 2 Input Sequences

LCS with Arbitrary Input Sequences Degree-Constrained

Spanning Tree

Minimal Spanning Tree

(25)
(26)

Sudoku is NPC

26

(27)

Minesweeper Consistency: Given a state of what purports to be a Minesweeper games, is it logically consistent?

(28)

Textbook Chapter 34.3 – NP-completeness and reducibility

28

(29)

Input: a Boolean formula with variables

Output: whether there is a truth assignment for the variables that satisfies the input Boolean formula

Stephan A. Cook [FOCS 1971] proved that

SAT can be solved in non-deterministic polynomial time

 SAT ∈ NP

If SAT can be solved in deterministic polynomial time, then so can any NP problems  SAT ∈ NP-hard

(30)

30

Problem A can be reduced (in polynomial time) to Problem B

= Problem B can be reduced (in polynomial time) from Problem A

We can find an algorithm that solves Problem B to help solve Problem A

If problem B has a polynomial-time algorithm, then so does problem A

Practice: design a MULTIPLY() function by ADD(), DIVIDE(), and SQUARE()

Algorithm for B

? Instance 𝛽 of B Answer for 𝛽 ? Answer for 𝛼 Instance 𝛼 of A

Algorithm for A

What is the complexity of Algorithm for A?

(31)

A reduction is an algorithm for transforming a problem instance into another

Definition

Reduction from A to B implies A is not harder than B

A ≤p Bif A can be reduced to B in polynomial time

Applications

Designing algorithms: given algorithm for B, we can also solve A

Classifying problems: establish relative difficulty between A and B

Proving limits: if A is hard, then so is B

31

Algorithm to decide B Reduction

Algorithm

Instance 𝛽 of B Yes

Instance 𝛼 of A

Algorithm to decide A No

This is why we need it for proving NP-completeness!

(32)

If A is an NP-hard problem and B can be reduced from A, then B is an NP-hard problem?

If A is an NP-complete problem and B can be reduced from A, then B is an NP-complete problem?

If A is an NP-complete problem and B can be reduced from A, then B is an NP-hard problem?

32

(33)

Q: Which one is harder?

A: They have equal difficulty.

Proof:

PARTITION ≤

p

KNAPSACK

KNAPSACK ≤

p

PARTITION

KNAPSACK: Given a set 𝑎1, … , 𝑎𝑛 of non-negative integers, and an integer 𝐾, decide if there is a subset 𝑃 ⊆

1, 𝑛 such that σ𝑖∈𝑃𝑎𝑖 = 𝐾.

PARTITION: Given a set of 𝑛 non-negative integers

𝑎1, … , 𝑎𝑛 , decide if there is a subset 𝑃 ⊆ 1, 𝑛 such that σ𝑖∈𝑃𝑎𝑖 = σ𝑖∉𝑃𝑎𝑖.

Polynomial-time reducible?

Polynomial-time reducible?

(34)

PARTITION ≤

p

KNAPSACK

If we can solve KNAPSACK, how can we use that to solve PARTITION?

KNAPSACK ≤

p

PARTITION

If we can solve PARTITION, how can we use that to solve KNAPSACK?

34

KNAPSACK: Given a set 𝑎1, … , 𝑎𝑛 of non-negative integers, and an integer 𝐾, decide if there is a subset 𝑃 ⊆

1, 𝑛 such that σ𝑖∈𝑃𝑎𝑖 = 𝐾.

PARTITION: Given a set of 𝑛 non-negative integers

𝑎1, … , 𝑎𝑛 , decide if there is a subset 𝑃 ⊆ 1, 𝑛 such that σ𝑖∈𝑃𝑎𝑖 = σ𝑖∉𝑃𝑎𝑖.

Polynomial-time reducible?

Polynomial-time reducible?

(35)

If we can solve KNAPSACK, how can we use that to solve PARTITION?

Polynomial-time reduction

Set

KNAPSACK: Given a set 𝑎1, … , 𝑎𝑛 of non-negative integers, and an integer 𝐾, decide if there is a subset 𝑃 ⊆ 1, 𝑛 such that σ𝑖∈𝑃𝑎𝑖 = 𝐾.

PARTITION: Given a set of 𝑛 non- negative integers 𝑎1, … , 𝑎𝑛 , decide if there is a subset 𝑃 ⊆ 1, 𝑛 such that σ𝑖∈𝑃𝑎𝑖 = σ𝑖∉𝑃𝑎𝑖.

5 6 7 8 5 6 7 8

p-time reduction

PARTITION instance KNAPSACK instance with

(36)

If we can solve KNAPSACK, how can we use that to solve PARTITION?

Polynomial-time reduction

Set

Correctness proof: KNAPSACK returns yes if and only if an equal-size

partition exists 36

Algorithm to decide KNAPSACK

P-time Reduction

Instance 𝛽 of KNAPSACK Instance 𝛼 of Yes

PARTITION

Algorithm to decide PARTITION No

5 6 7 8 5 6 7 8

p-time reduction

PARTITION instance KNAPSACK instance with

(37)

If we can solve PARTITION, how can we use that to solve KNAPSACK?

Polynomial-time reduction

Set

Add ,

KNAPSACK: Given a set 𝑎1, … , 𝑎𝑛 of non-negative integers, and an integer 𝐾, decide if there is a subset 𝑃 ⊆ 1, 𝑛 such that σ𝑖∈𝑃𝑎𝑖 = 𝐾.

PARTITION: Given a set of 𝑛 non- negative integers 𝑎1, … , 𝑎𝑛 , decide if there is a subset 𝑃 ⊆ 1, 𝑛 such that σ𝑖∈𝑃𝑎𝑖 = σ𝑖∉𝑃𝑎𝑖.

5 6 7 8 5 6 7 8

p-time reduction

PARTITION instance

48 52

KNAPSACK instance with

(38)

If we can solve PARTITION, how can we use that to solve KNAPSACK?

Polynomial-time reduction

Set

Add ,

Correctness proof: PARTITION returns yes if and only if there is a

subset 𝑃 ⊆ 1, 𝑛 such that σ𝑖∈𝑃 𝑎𝑖 = 𝐾 38

5 6 7 8 5 6 7 8

p-time reduction

KNAPSACK instance with PARTITION instance

48 52

Algorithm to decide PARTITION

P-time Reduction

Instance 𝛽 of PARTITION Instance 𝛼 of Yes

KNAPSACK

Algorithm to decide KNAPSACK No

(39)

Polynomial-time reduction

Set

Add ,

Correctness proof: PARTITION returns yes if and only if there is a subset 𝑃 ⊆ 1, 𝑛 such that σ𝑖∈𝑃 𝑎𝑖 = 𝐾

“if” direction

𝑎1 𝑎2 𝑎3 𝑎4 𝑎1 𝑎4 𝑎5 𝑎2 𝑎3 𝑎6

PARTITION returns yes!

(40)

Polynomial-time reduction

Set

Add ,

Correctness proof: PARTITION returns yes if and only if there is a subset 𝑃 ⊆ 1, 𝑛 such that σ𝑖∈𝑃 𝑎𝑖 = 𝐾

“only if” direction

Because , if PARTITION returns yes, each set has 4𝐻 + 𝐾

𝑎1, … , 𝑎𝑛 must be divided into 2𝐻 − 𝐾 and 𝐾

40

𝑎6

𝑎2 𝑎3 𝑎5 𝑎1 𝑎4 𝑎1 𝑎2 𝑎3 𝑎4

a subset 𝑃 s.t. σ𝑖∈𝑃𝑎𝑖 = 𝐾

(41)

Definition

Reduction from A to B implies A is not harder than B

A ≤p Bif A can be reduced to B in polynomial time

NP-completeness proofs

Goal: prove that B is NP-hard

Known: A is NP-complete/NP-hard

Approach: construct a polynomial-time reduction algorithm to convert 𝛼 to 𝛽

Correctness: if we can solve B, then A can be solved  A ≤p B

B is no easier than A  A is NP-hard, so B is NP-hard

41

Algorithm to decide B Reduction

Algorithm

Instance 𝛽 of B Yes

Instance 𝛼 of A

Algorithm to decide A No

If the reduction is not p-time, does this argument hold?

(42)

42

(43)

Focus on decision problems

A language L over σ is any set of strings made up of symbols from σ

Every language L over σ is a subset of σ

An algorithm A accepts a string if

The language accepted by an algorithm A is the set of strings

An algorithm A rejects a string x if

The formal-language framework allows us to express concisely the relation between decision problems and algorithms that solve them.

(44)

NP-Complete (NPC): class of decision problems in both NP and NP-hard

In other words, a decision problem L is NP-complete if

1. L ∈ NP

2. L ∈ NP-hard (that is, L’ ≤p L for every L’ ∈ NP)

44

L1 L2 L3 :

L

p

all NP problems

How to prove L is NP-hard ?

L1 L2 L3 :

p

all NP problems

L known

NPC problem

p held by

definition

Goal: prove polynomial- time reduction

(45)

If are languages s.t. , then L2 ∈ P implies L1 ∈ P.

A2 Transform

function f 𝑥 𝑓 𝑥

A1

(46)

46

Given a Boolean combinational circuit composed of AND, OR, and NOT gates, is it satisfiable?

Satisfiable: there exists an assignment s.t. outputs = 1

Satisfiable Unsatisfiable

(47)

CIRCUIT-SAT can be solved in non-deterministic polynomial time

 ∈ NP

If CIRCUIT-SAT can be solved in deterministic polynomial time, then so can any NP problems

 ∈ NP-hard

(proof in textbook 34.3)

CIRCUIT-SAT is NP-complete

CIRCUIT-SAT = {<C>: C is a satisfiable Boolean combinational circuit}

(48)

48

If one proves that SAT can be solved by a polynomial-time algorithm, then NP = P.

If somebody proves that SAT cannot be solved by any

polynomial-time algorithm, then NP ≠ P.

(49)

1. CNF-SAT

2. 0-1 INTEGER PROGRAMMING

3. CLIQUE

4. SET PACKING

5. VERTEX COVER

6. SET COVERING

7. FEEDBACK ARC SET

8. FEEDBACK NODE SET

9. DIRECTED HAMILTONIAN CIRCUIT

10. UNDIRECTED HAMILTONIAN CIRCUIT

11. 3-SAT

12. CHROMATIC NUMBER

13. CLIQUE COVER

14. EXACT COVER

15. 3-dimensional MATCHING

16. STEINER TREE

17. HITTING SET

18. KNAPSACK

19. JOB SEQUENCING

20. PARTITION

21. MAX-CUT

(50)

50

(51)

Given a Boolean formula Φ with variables, is there a variable assignment satisfying Φ

∧ (AND), ∨ (OR), ¬ (NOT), → (implication), ↔ (if and only if)

Satisfiable: Φ is evaluated to 1

(52)

Is SAT ∈ NP-Complete?

To prove that SAT is NP-Complete, we show that

SAT ∈ NP

SAT ∈ NP-hard (CIRCUIT-SAT ≤p SAT)

1) CIRCUIT-SAT is a known NPC problem

2) Construct a reduction f transforming every CIRCUIT-SAT instance to an SAT instance

3) Prove that x ∈ CIRCUIT-SAT iff f(x) ∈ SAT

4) Prove that f is a polynomial time transformation

52

SAT = {Φ | Φ is a Boolean formula with a satisfying assignment }

(53)

Polynomial-time verification: replaces each variable in the formula with the corresponding value in the certificate and then evaluates the expression

53

initial configuration

polynomial

(54)

1) CIRCUIT-SAT is a known NPC problem

2) Construct a reduction f transforming every CIRCUIT-SAT instance to an SAT instance

Assign a variable to each wire in circuit C

Represent the operation of each gate using a formula, e.g.

Φ = AND the output variable and the operations of all gates

54

(55)

3. Prove that x ∈ CIRCUIT-SAT ↔ f(x) ∈ SAT

x ∈ CIRCUIT-SAT → f(x) ∈ SAT

f(x) ∈ SAT → x ∈ CIRCUIT-SAT

4. f is a polynomial time transformation CIRCUIT-SAT ≤p SAT  SAT ∈ NP-hard

(56)

3-CNF-SAT: Satisfiability of Boolean formulas in 3-conjunctive normal form (3-CNF)

3-CNF = AND of clauses, each of which is the OR of exactly 3 distinct literals

A literal is an occurrence of a variable or its negation, e.g., x1 or ¬x1

56

 satisfiable

(57)

Is 3-CNF-SAT ∈ NP-Complete?

To prove that SAT is NP-Complete, we show that

3-CNF-SAT ∈ NP

3-CNF-SAT ∈ NP-hard (SAT ≤p 3-CNF-SAT)

1) SAT is a known NPC problem

2) Construct a reduction f transforming every SAT instance to an 3-CNF-SAT instance

3) Prove that x ∈ SAT iff f(x) ∈ 3-CNF-SAT

4) Prove that f is a polynomial time transformation

3-CNF-SAT = {Φ | Φ is a Boolean formula in 3-conjunctive normal form (3-CNF) with a satisfying assignment }

We focus on the reduction construction from now on, but remember that a full proof requires showing that all other conditions are true as well

(58)

a) Construct a binary parser tree for an input formula Φ and introduce a variable yi for the output of each internal node

58

(59)

b) Rewrite Φ as the AND of the root variable and clauses describing the operation of each node

(60)

c) Convert each clause Φi’ to CNF

Construct a truth table for each clause Φi’

Construct the disjunctive normal form for ¬Φi’

Apply DeMorgan’s Law to get the CNF formula Φi’’

60

𝒚𝟏 𝒚𝟐 𝒚𝟐 Φ1 ¬Φ1

1 1 1 0 1

1 1 0 1 0

1 0 1 0 1

1 0 0 0 1

0 1 1 1 0

0 1 0 0 1

0 0 1 1 0

0 0 0 1 0

𝒚𝟏 𝒚𝟐 𝒚𝟐 Φ1

1 1 1 0

1 1 0 1

1 0 1 0

1 0 0 0

0 1 1 1

0 1 0 0

0 0 1 1

0 0 0 1

(61)

d) Construct Φ’’’ in which each clause Ci exactly 3 distinct literals

3 distinct literals:

2 distinct literals:

1 literal only:

Φ’’’ is satisfiable iff Φ is satisfiable

All transformation can be done in polynomial time

 3-CNF-SAT is NP-Complete

(62)

Proving NP-Completeness: L ∈ NPC iff L ∈ NP and L ∈ NP-hard

Step-by-step approach for proving L in NPC:

Prove L ∈ NP

Prove L ∈ NP-hard

1) Select a known NPC problem C

2) Construct a reduction f transforming every instance of C to an instance of L

3) Prove that

4) Prove that f is a polynomial time transformation L ∈ NP

62

P ≠ NP

P = NP

(63)

Course Website: http://ada.miulab.tw Email: ada-ta@csie.ntu.edu.tw

63

Important announcement will be sent to @ntu.edu.tw mailbox

& post to the course website

參考文獻

相關文件

✓ Combining an optimal solution to the subproblem via greedy can arrive an optimal solution to the original problem.. Prove that there is always an optimal solution to the

vertices’ edges, in this shortest path, the left edge must be relaxed before the right edge.  One phase of improvement

 Combine: find closet pair with one point in each region, and return the best of three

▪ Step 2: Run DFS on the transpose

Greedy-Choice Property : making locally optimal (greedy) choices leads to a globally optimal

 From a source vertex, systematically follow the edges of a graph to visit all reachable vertices of the graph.  Useful to discover the structure of

• As the binary quadratic programming program is NP-hard in general, identifying polynomially solvable subclasses of binary quadratic programming problems not only offers the-

✓ Express the solution of the original problem in terms of optimal solutions for subproblems. Construct an optimal solution from