Complexity 373F19 - Nisarg Shah & Karan Singh 1 Recap Linear - - PowerPoint PPT Presentation

complexity
SMART_READER_LITE
LIVE PREVIEW

Complexity 373F19 - Nisarg Shah & Karan Singh 1 Recap Linear - - PowerPoint PPT Presentation

CSC373 Weeks 7 & 8: Complexity 373F19 - Nisarg Shah & Karan Singh 1 Recap Linear Programming Standard formulation Slack formulation Simplex Duality 373F19 - Nisarg Shah & Karan Singh 2 And Now


slide-1
SLIDE 1

CSC373 Weeks 7 & 8: Complexity

373F19 - Nisarg Shah & Karan Singh 1

slide-2
SLIDE 2

Recap

373F19 - Nisarg Shah & Karan Singh 2

  • Linear Programming

➢ Standard formulation ➢ Slack formulation ➢ Simplex ➢ Duality

slide-3
SLIDE 3

And Now…

373F19 - Nisarg Shah & Karan Singh 3

  • Applications of linear programming

➢ Shortest path ➢ Network flow

  • A note about integer programming
  • Complexity

➢ Turing machines, computability, efficient computation ➢ P, NP, and NP-completeness ➢ Reductions ➢ Idea behind NP-completeness of SAT and 3SAT ➢ NP vs co-NP ➢ Other complexity classes

slide-4
SLIDE 4

Network Flow via LP

373F19 - Nisarg Shah & Karan Singh 4

  • Problem

➢ Input: directed graph 𝐻 = (𝑊, 𝐹), edge capacities

𝑑: 𝐹 → ℝ≥0

➢ Output: Value 𝑤 𝑔∗ of a maximum flow 𝑔∗

  • Flow 𝑔 is valid if:

➢ Capacity constraints: ∀ 𝑣, 𝑤 ∈ 𝐹: 0 ≤ 𝑔 𝑣, 𝑤 ≤ 𝑑(𝑣, 𝑤) ➢ Flow conservation: ∀𝑣: σ 𝑣,𝑤 ∈𝐹 𝑔 𝑣, 𝑤 = σ 𝑤,𝑣 ∈𝐹 𝑔 𝑤, 𝑣

  • Maximize 𝑤 𝑔 = σ 𝑡,𝑤 ∈𝐹 𝑔 𝑡, 𝑤

Linear objective! Linear constraints

slide-5
SLIDE 5

Network Flow via LP

373F19 - Nisarg Shah & Karan Singh 5

(𝑡,𝑤)∈𝐹

𝑔

𝑡𝑤

0 ≤ 𝑔

𝑣𝑤 ≤ 𝑑 𝑣, 𝑤

(𝑣,𝑤)∈𝐹

𝑔

𝑣𝑤 =

(𝑤,𝑥)∈𝐹

𝑔

𝑤,𝑥

for all (𝑣, 𝑤) ∈ 𝐹 for all 𝑤 ∈ 𝑊\{𝑡, 𝑢} maximize

Exercise: Write the dual of this LP. What is the dual trying to find?

slide-6
SLIDE 6

Shortest Path via LP

  • Problem

➢ Input: directed graph 𝐻 = 𝑊, 𝐹 , edge weights

𝑥: 𝐹 → ℝ≥0, source vertex 𝑡, target vertex 𝑢

➢ Output: weight of the shortest-weight path from 𝑡 to 𝑢

  • Variables: for each vertex 𝑤, we have variable 𝑒𝑤

Why max? If objective was min., then we could set all variables 𝑒𝑤 to 0. Exercise: prove formally that this works!

slide-7
SLIDE 7

But…but…

373F19 - Nisarg Shah & Karan Singh 7

  • For these problems, we have different

combinatorial algorithms that are much faster and run in strongly polynomial time

  • Why would we use LP?
  • For some problems, we don’t have faster

algorithms than solving them via LP

slide-8
SLIDE 8

Multicommodity-Flow

373F19 - Nisarg Shah & Karan Singh 8

  • Problem:

➢ Input: directed graph 𝐻 = (𝑊, 𝐹), edge capacities 𝑑: 𝐹 →

ℝ≥0, 𝑙 commodities (𝑡𝑗, 𝑢𝑗, 𝑒𝑗), where 𝑡𝑗 is source of commodity 𝑗, 𝑢𝑗 is sink, and 𝑒𝑗 is demand.

➢ Output: valid multicommodity flow 𝑔

1, 𝑔 2, … , 𝑔 𝑙 , where

𝑔

𝑗 has value 𝑒𝑗 and all 𝑔 𝑗 jointly satisfy the constraints

The only known polynomial time algorithm for this problem is based on solving LP!

slide-9
SLIDE 9

Integer Linear Programming

373F19 - Nisarg Shah & Karan Singh 9

  • Variable values are restricted to be integers
  • Example:

➢ Input: 𝑑 ∈ ℝ𝑜, 𝑐 ∈ ℝ𝑛, 𝐵 ∈ ℝ𝑛×𝑜 ➢ Goal:

Maximize 𝑑𝑈𝑦 Subject to 𝐵𝑦 ≤ 𝑐 𝒚 ∈ {𝟏, 𝟐}𝒐

  • Does this make the problem easier or harder?

➢ Harder. We’ll prove that this is “NP-complete”.

slide-10
SLIDE 10

LPs are everywhere…

373F19 - Nisarg Shah & Karan Singh 10

➢ Microeconomics ➢ Manufacturing ➢ VLSI (very large scale integration) design ➢ Logistics/transportation ➢ Portfolio optimization ➢ Bioengineering (flux balance analysis) ➢ Operations research more broadly: maximize profits or

minimize costs, use linear models for simplicity

➢ Design of approximation algorithms ➢ Proving theorems, as a proof technique ➢ …

slide-11
SLIDE 11

Introduction to Complexity

373F19 - Nisarg Shah & Karan Singh 11

  • You have a problem at hand
  • You try every technique known to humankind for

finding a polynomial time algorithm, but fail.

  • You try every technique known to humankind for

proving that there cannot exist a polynomial time algorithm for your problem, but fail.

  • What do you do?

➢ Prove that it is NP-complete, of course!

slide-12
SLIDE 12

Turing Machines

373F19 - Nisarg Shah & Karan Singh 12

  • “Which problems can a computer (not) solve in a

certain amount of time?”

➢ How do we mathematically define what a computer is?

  • Alan Turing (“Father of Computer Science”), 1936

➢ Introduced a mathematical model ➢ “Turing machine” ➢ All present-day computers can be simulated by a Turing

machine

➢ Fun fact: So can all the quantum computers

  • But TM might take longer to solve the same problem
slide-13
SLIDE 13

Turing Machines

373F19 - Nisarg Shah & Karan Singh 13

  • We won’t formally introduce…but at a high level…
  • Turing machine

➢ Tape

  • Input is given on tape
  • Intermediate computations can be written there
  • Output must to be written there

➢ Head pointer

  • Initially pointing at start of input on tape

➢ Maintains an internal “state” ➢ A transition function describes how to change state,

move head pointer, and read/write symbols on tape

slide-14
SLIDE 14

Computability

373F19 - Nisarg Shah & Karan Singh 14

  • Church-Turing Hypothesis

➢ “Everything that is computable can be computed by a

Turing machine”

➢ Widely accepted, cannot be “proven” ➢ There are problems which a Turing machine cannot solve,

regardless of the amount of time available

  • E.g., the halting problem
  • What about the problems we can solve? How do

we define the time required?

➢ Need to define an encoding of the input and output

slide-15
SLIDE 15

Encoding

373F19 - Nisarg Shah & Karan Singh 15

  • What can we write on the tape?

➢ 𝑇 = a set of finite symbols ➢ 𝑇∗ = ڂ𝑜≥0 𝑇𝑜 = set of all finite strings using symbols from 𝑇

  • Input: 𝑥 ∈ 𝑇∗

➢ Length of input = |𝑥| = length of 𝑥 on tape

  • Output: 𝑔 𝑥 ∈ 𝑇∗

➢ Length of output = 𝑔 𝑥 ➢ Decision problems: output = “YES” or “NO”

  • E.g. “does there exist a flow of value at least 7 in this network?”
slide-16
SLIDE 16

Encoding

373F19 - Nisarg Shah & Karan Singh 16

  • Example:

➢ “Given 𝑏1, 𝑏2, … , 𝑏𝑜, compute σ𝑗=1

𝑜

𝑏𝑗”

  • Suppose we are told that 𝑏𝑗 ≤ 𝐷 for all 𝑗

➢ What |𝑇| should we use?

  • 𝑇 = {0,1} ( 𝑇 = 2, binary representation)
  • Length of input = 𝑃 log2 𝑏1 + ⋯ + log2 𝑏𝑜 = 𝑃 𝑜 log2 𝐷
  • What about 3-ary ( 𝑇 = 3) or 18-ary ( 𝑇 = 18)?
  • Only changes the length by a constant factor, still 𝑃(𝑜 log 𝐷)
  • What about unary (conceptually, 𝑇 = 1)?
  • Length blows up exponentially to 𝑃 𝑜𝐷
  • Binary is already good enough, but unary isn’t
slide-17
SLIDE 17

Efficient Computability

373F19 - Nisarg Shah & Karan Singh 17

  • Polynomial-time computability

➢ A TM solves a problem in polynomial time if there is a

polynomial 𝑞 such that on every instance of 𝑜-bit input and 𝑛-bit output, the TM halts in at most 𝑞(𝑜, 𝑛) steps

➢ Polynomial: 𝑜, 𝑜2, 5𝑜100 + 1000𝑜3, 𝑜 log100 𝑜 = 𝑝 𝑜1.001 ➢ Non-polynomial: 2𝑜, 2 𝑜, 2log2 𝑜

  • Extended Church-Turing Hypothesis

➢ “Everything that is efficiently computable is computable by

a TM in polynomial time”

➢ Much less widely accepted, especially today ➢ But in this course, efficient = polynomial-time

If you ask the Turing machine to write a 2𝑜-bit output, it’s only reasonable to let it take 2𝑜 time…but usually, we’ll look at problems where output is O(length of input), so we can ignore this 𝑛

slide-18
SLIDE 18

P

373F19 - Nisarg Shah & Karan Singh 18

  • P (polynomial time)

➢ The class of all decision problems computable by a TM in

polynomial time

  • Examples

➢ Addition, multiplication, square root ➢ Shortest paths ➢ Network flow ➢ Fast Fourier transform ➢ Checking if a given number is a prime

[Agrawal-Kayal-Saxena 2002]

➢ …

slide-19
SLIDE 19

NP

373F19 - Nisarg Shah & Karan Singh 19

  • NP (nondeterministic polynomial time) intuition

➢ Subset sum problem:

Given an array {−7, −3, −2, 5, 8}, is there a zero-sum subset?

➢ Enumerating all subsets is exponential ➢ BUT given a subset {-7, -2} or {-3, -2, 5}, we can check in

polynomial time whether it has zero sum

➢ A nondeterministic Turing machine could “guess” the

subset and then test if it has zero sum in polynomial time

slide-20
SLIDE 20

NP

373F19 - Nisarg Shah & Karan Singh 20

  • NP (nondeterministic polynomial time)

➢ The class of all decision problems for which a YES answer

can be verified by a TM in polynomial time given polynomial length “advice” or “witness”.

➢ There is a polynomial-time verifier TM 𝑊 and another

polynomial 𝑞 such that

  • For all YES inputs 𝑦, there exists 𝑧 with 𝑧 = 𝑞 𝑦
  • n which

𝑊(𝑦, 𝑧) returns YES

  • For all NO inputs 𝑦, 𝑊(𝑦, 𝑧) returns NO for every 𝑧

➢ Informally: “Whenever the answer is YES, there’s a short

proof of it.”

slide-21
SLIDE 21

co-NP

373F19 - Nisarg Shah & Karan Singh 21

  • co-NP

➢ Same as NP, except whenever the answer is NO, we want

there to be a short proof of it

  • Open questions

➢ NP = co-NP? ➢ P = NP ∩ co-NP? ➢ And…drum roll please…

𝑄 = 𝑂𝑄?

slide-22
SLIDE 22

P versus NP

373F19 - Nisarg Shah & Karan Singh 22

  • Lance Fortnow in his article on P and NP in

Communications of the ACM, Sept 2009

“The P versus NP problem has gone from an interesting problem related to logic to perhaps the most fundamental and important mathematical question of

  • ur time, whose importance only grows

as computers become more powerful and widespread.”

slide-23
SLIDE 23

Millenium Problems

373F19 - Nisarg Shah & Karan Singh 23

  • Award of $1,000,000 for each problem by Clay

Math institute

  • 1. Birch and Swinnerton-Dyer Conjecture
  • 2. Hodge Conjecture
  • 3. Navier-Stokes Equations
  • 4. P = NP?
  • 5. Poincare Conjecture (Solved)1
  • 6. Riemann Hypothesis
  • 7. Yang-Mills Theory

1Solved by Grigori Perelman (2003): Prize unclaimed

Claim: Worth >> $1M

slide-24
SLIDE 24

Cook’s Conjecture

373F19 - Nisarg Shah & Karan Singh 24

  • Cook’s conjecture

➢ (And every sane person’s belief…) ➢ 𝑄 is likely not equal to 𝑂𝑄

  • Why do we believe this?

➢ There is a large class of problems (NP-complete) ➢ By now, contains thousands and thousands of problems ➢ Each problem is the “hardest problem in NP” ➢ If you can efficiently solve any one of them, you can

efficiently solve every problem in NP

  • Despite decades of effort, no polynomial time solution has been

found for any of them

slide-25
SLIDE 25

Reductions

373F19 - Nisarg Shah & Karan Singh 25

  • Problem 𝐵 is p-reducible to problem 𝐶 if an

“oracle” (subrouting) for 𝐶 can be used to efficiently solve 𝐵

➢ You can solve 𝐵 by making polynomially many calls to the

  • racle and doing additional polynomial computation
  • Question: If 𝐵 is p-reducible to 𝐶, then which of

the following is true?

a) If 𝐵 cannot be solved efficiently, then neither can 𝐶. b) If 𝐶 cannot be solved efficiently, then neither can 𝐵. c) Both. d) None.

slide-26
SLIDE 26

Reductions

373F19 - Nisarg Shah & Karan Singh 26

  • Problem 𝐵 is p-reducible to problem 𝐶 (denoted

𝐵 ≤𝑞 𝐶) if an “oracle” (subrouting) for 𝐶 can be used to efficiently solve 𝐵

➢ You can solve 𝐵 by making polynomially many calls to the

  • racle and doing additional polynomial computation
  • Question: If I want to prove that my problem 𝑌 is

“hard”, I should:

a) Reduce my problem to a known hard problem. b) Reduce a known hard problem to my problem. c) Both. d) None.

slide-27
SLIDE 27

NP-completeness

373F19 - Nisarg Shah & Karan Singh 27

  • NP-completeness

➢ A problem 𝐶 is NP-complete if it is in NP and every

problem 𝐵 in NP is p-reducible to 𝐶

➢ Hardest problems in NP ➢ If one of them can be solved efficiently, every problem in

NP can be solved efficiently, implying P=NP

  • Observation:

➢ If 𝐵 is in NP, and some NP-complete problem 𝐶 is p-

reducible to 𝐵, then 𝐵 is NP-complete too

  • “If I could solve A, then I could solve B, then I could solve any

problem in NP”

slide-28
SLIDE 28

NP-completeness

373F19 - Nisarg Shah & Karan Singh 28

  • But this uses an already known NP-complete

problem to prove another problem is NP-complete

  • How do we find the first NP-complete problem?

➢ How do we know there are any NP-complete problems at

all?

➢ Key result by Cook ➢ First NP-complete problem: SAT

  • By a reduction from an arbitrary problem in NP to SAT
  • “From first principles”
slide-29
SLIDE 29

CNF Formulas

373F19 - Nisarg Shah & Karan Singh 29

  • Conjunctive normal form (CNF)

➢ Boolean variables 𝑦1, 𝑦2, … , 𝑦𝑜 ➢ Their negations ҧ

𝑦1, ҧ 𝑦2, … , ҧ 𝑦𝑜

➢ Literal ℓ: a variable or its negation ➢ Clause 𝐷 = ℓ1 ∨ ℓ2 ∨ ⋯ ∨ ℓ𝑠 is a disjunction of literals ➢ CNF formula 𝜒 = 𝐷1 ∧ 𝐷2 ∧ ⋯ ∧ 𝐷𝑛 is a conjunction of clauses

  • 𝑙CNF: Each clause has at most 𝑙 literals
  • We’ll abuse notation a little and assume there are exactly 𝑙
  • Example of 3CNF

𝜒 = ҧ 𝑦1 ∨ 𝑦2 ∨ 𝑦3 ∧ 𝑦1 ∨ ҧ 𝑦2 ∨ 𝑦3 ∧ ҧ 𝑦1 ∨ 𝑦2 ∨ 𝑦4 ∧ ( ҧ 𝑦3 ∨ ҧ 𝑦4 ∨ 𝑦1)

slide-30
SLIDE 30

SAT and 3SAT

373F19 - Nisarg Shah & Karan Singh 30

  • Example of 3CNF

𝜒 = ҧ 𝑦1 ∨ 𝑦2 ∨ 𝑦3 ∧ 𝑦1 ∨ ҧ 𝑦2 ∨ 𝑦3 ∧ ҧ 𝑦1 ∨ 𝑦2 ∨ 𝑦4 ∧ ( ҧ 𝑦3 ∨ ҧ 𝑦4 ∨ 𝑦1)

  • SAT

➢ A CNF formula 𝜒 is satisfiable if there is an assignment of

truth values (TRUE/FALSE) to variables under which the formula evaluates to TRUE

  • That means, in each clause, at least one literal is TRUE

➢ SAT: “Given a CNF formula 𝜒, is it satisfiable?” ➢ 3SAT: “Given a 3CNF formula 𝜒, is it satisfiable?”

slide-31
SLIDE 31

SAT and 3SAT

373F19 - Nisarg Shah & Karan Singh 31

  • Cook-Levin Theorem

➢ SAT (and even 3SAT) is NP-complete

  • Doesn’t use any known NP-complete problem

➢ Directly reduces any NP problem to SAT ➢ Reduction is a bit complex, so we’ll defer it until a bit

later, after we’ve seen some other reductions and are more comfortable with the reduction framework

➢ But for now, let’s assume SAT is NP-complete, and reduce

it to a bunch of other problems (and then those problems to other problems…)

slide-32
SLIDE 32

NP-Complete Examples

373F19 - Nisarg Shah & Karan Singh 32

  • NP-complete problems

➢ SAT = first NP complete problem ➢ Decision TSP: Is there a route visiting all 𝑜 cities with total

distance at most 𝑙?

➢ 3-Colorabitility: Can the vertices of a graph be colored

with at most 3 colors such that no two adjacent vertices have the same color?

➢ Karp’s 21 NP-complete problems

  • co-NP-complete

➢ Tautology problem (“negation” of SAT)

slide-33
SLIDE 33

Complexity

373F19 - Nisarg Shah & Karan Singh 33 By Behnam Esfahbod, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=3532181

slide-34
SLIDE 34

373F19 - Nisarg Shah & Karan Singh 34

⋮ ⋮

slide-35
SLIDE 35

373F19 - Nisarg Shah & Karan Singh 35

slide-36
SLIDE 36

Just A Tad Bit of History

373F19 - Nisarg Shah & Karan Singh 36

  • [Cook 1971]

➢ Proved 3SAT is NP-complete in seminal paper

  • [Karp 1972]

➢ Showed that 20 other problems are also NP-complete ➢ “Karp's 21 NP-complete problems” ➢ Renewed interest in this idea

  • 1982: Cook won the Turing award
slide-37
SLIDE 37
  • Problem

➢ Input: Undirected graph 𝐻 = (𝑊, 𝐹), integer 𝑙 ➢ Question: Does there exist a subset of vertices 𝑇 ⊆ 𝑊

with 𝑇 = 𝑙 such that for each edge, at most one of its endpoints is in 𝑇?

Independent Set

373F19 - Nisarg Shah & Karan Singh 37

= independent set Example:

  • Does this graph have an

independent set of size 6?

  • Yes!
  • Does this graph have an

independent set of size 7?

  • No!
slide-38
SLIDE 38
  • Claim: Independent Set is in NP

➢ Recall: We need to show that there is a polynomial-time

algorithm which

  • Can accept every YES instance with the right polynomial-size advice
  • Will not accept a NO instance with any advice

➢ Advice: the actual independent set 𝑇

  • Algorithm: Simply check if 𝑇 is an independent set and 𝑇 = 𝑙
  • Simple!

Independent Set

373F19 - Nisarg Shah & Karan Singh 38

slide-39
SLIDE 39
  • Claim: 3SAT ≤𝑞 Independent Set

➢ Given a formula 𝜒 of 3SAT with 𝑙 clauses, construct an

instance (𝐻, 𝑙) of Independent Set as follows

  • Create 3 vertices for each clause (one for each literal)
  • Connect them in a triangle
  • Connect the vertex of each literal to each of its negations

Independent Set

373F19 - Nisarg Shah & Karan Singh 39

slide-40
SLIDE 40

➢ Why does this work?

  • 3SAT = YES (𝜒 has satisfying assignment) ⇒ Independent Set = YES
  • From each clause, take any literal that is TRUE in the assignment
  • Independent Set = YES ⇒ 3SAT = YES
  • Independent set 𝑇 must contain one vertex from each triangle
  • No literal and its negation are both in 𝑇
  • Set literals in 𝑇 to TRUE, their negations to FALSE, and the rest to

arbitrary values

Independent Set

373F19 - Nisarg Shah & Karan Singh 40

slide-41
SLIDE 41

Different Types of Reductions

373F19 - Nisarg Shah & Karan Singh 41

  • 𝐵 ≤ 𝐶

➢ Karp reductions

  • Take an arbitrary instance of 𝐵, and in polynomial time, construct

a single instance of 𝐶 with the same answer

  • Very restricted type of reduction
  • The reduction we just constructed was a Karp reduction

➢ Turing/Cook reductions

  • Take an arbitrary instance of 𝐵, and solve it by making

polynomially many calls to an oracle for solving 𝐶 and some polynomial-time extra computation

  • Very general reduction
  • In this course, we’ll allow Turing/Cook reductions, but whenever

possible, see if you can construct a Karp reduction

slide-42
SLIDE 42

Subset Sum

373F19 - Nisarg Shah & Karan Singh 42

  • Problem

➢ Input: Set of integers 𝑇 = {𝑥1, … , 𝑥𝑜}, integer 𝑋 ➢ Question: Is there 𝑇′ ⊆ 𝑇 that adds up to exactly 𝑋?

  • Example

➢ 𝑇 = {1, 4, 16, 64, 256, 1040, 1041, 1093, 1284, 1344}

and 𝑋 = 3754?

➢ Yes!

  • 1 + 16 + 64 + 256 + 1040 + 1093 + 1284 = 3754
slide-43
SLIDE 43
  • Claim: Subset Sum is in NP

➢ Recall: We need to show that there is a polynomial-time

algorithm which

  • Can accept every YES instance with the right polynomial-size advice
  • Will not accept a NO instance with any advice

➢ Advice: the actual subset 𝑇′

  • Algorithm: Simply check that elements of 𝑇′ sum to 𝑋
  • Simple!

Subset Sum

373F19 - Nisarg Shah & Karan Singh 43

slide-44
SLIDE 44
  • Claim: 3SAT ≤𝑞 Subset Sum

➢ Given a formula 𝜒 of 3SAT, we want to construct (𝑇, 𝑋) of

Subset Sum with the same answer

➢ In the table in the following slide:

  • Columns are for variables and clauses
  • Each row is a number in 𝑇, represented in decimal
  • Number for literal ℓ : has 1 in its variable column and in the column
  • f every clause where that literal appears
  • Number selected = literal set to TRUE
  • “Dummy” rows: can help make the sum in a clause column 4 if and
  • nly if at least one literal is set to TRUE

Subset Sum

373F19 - Nisarg Shah & Karan Singh 44

slide-45
SLIDE 45
  • Claim: 3SAT ≤𝑞 Subset Sum

Subset Sum

373F19 - Nisarg Shah & Karan Singh 45

slide-46
SLIDE 46
  • Note

➢ The Subset Sum instance we constructed has large numbers

  • Something like 10#𝑤𝑏𝑠𝑗𝑏𝑐𝑚𝑓𝑡+#𝑑𝑚𝑏𝑣𝑡𝑓𝑡
  • Numbers are exponential in size of the original 3CNF instance, but it
  • nly takes polynomially many bits to write these numbers

➢ Can we hope to construct Subset Sum instance with

numbers that are only 𝑞𝑝𝑚𝑧(#𝑤𝑏𝑠𝑗𝑏𝑐𝑚𝑓𝑡, #𝑑𝑚𝑏𝑡𝑣𝑡𝑓𝑡) large?

  • Unlikely.
  • Like Knapsack, Subset Sum can be solved in pseudo-polynomial time

(i.e. we can solve Subset Sum in polytime if the numbers are only polynomially large in value).

Subset Sum

373F19 - Nisarg Shah & Karan Singh 46

slide-47
SLIDE 47

3-Coloring

373F19 - Nisarg Shah & Karan Singh 47

  • Problem

➢ Input: Undirected graph 𝐻 = (𝑊, 𝐹) ➢ Question: Can we color each vertex of 𝐻 using at most

three colors such that no two adjacent vertices have the same color?

slide-48
SLIDE 48
  • Claim: 3-coloring is in NP

➢ Recall: We need to show that there is a polynomial-time

algorithm which

  • Can accept every YES instance with the right polynomial-size advice
  • Will not accept a NO instance with any advice

➢ Advice: colors of the nodes in a valid 3-coloring

  • Algorithm: Simply check that this is a valid 3-coloring
  • Simple!

3-Coloring

373F19 - Nisarg Shah & Karan Singh 48

slide-49
SLIDE 49

3-Coloring

373F19 - Nisarg Shah & Karan Singh 49

  • Claim: 3SAT ≤𝑞 3-Coloring

➢ Given a 3SAT formula 𝜒, we want to construct a graph 𝐻

such that 𝐻 is 3-colorable if and only if 𝜒 has a satisfying assignment

➢ We want a satisfying assignment of 𝜒 to correspond to a

valid 3-coloring of 𝐻

  • Each true literal should have color T
  • Each false literal should have color F
  • We need to make sure they don’t get the third color
slide-50
SLIDE 50

3-Coloring

373F19 - Nisarg Shah & Karan Singh 50

➢ Given a 3SAT formula 𝜒, we construct a graph 𝐻 as follows

  • Create 3 new nodes T, F, and B; connect them in a triangle
  • Create a node for each literal, connect it to its negation and to B
  • So T-F-B have different colors and B-𝑦𝑗- ҧ

𝑦𝑗 have different colors

  • Each literal has the color of T/F and its negation has the other color
slide-51
SLIDE 51

3-Coloring

373F19 - Nisarg Shah & Karan Singh 51

➢ Claim: valid 3-coloring ⇒ valid truth assignment

  • Each literal node must be colored T or F
  • If a literal is T, its negation must be F
  • We can set all literals with color T to be TRUE
  • Valid truth assignment
slide-52
SLIDE 52

3-Coloring

373F19 - Nisarg Shah & Karan Singh 52

➢ What about clauses?

  • For each clause, add the following gadget with 6 nodes and 13 edges
  • Claim: Clause gadget is 3-colorable if and only if at least one of the

nodes corresponding to the literals in the clause is assigned color of T

slide-53
SLIDE 53

3-Coloring

373F19 - Nisarg Shah & Karan Singh 53

➢ Claim: Valid 3-coloring ⇒ truth assignment satisfies 𝜒

  • Suppose a clause 𝐷𝑗 is not satisfied, so all its three literals must be F
  • Then the 3 nodes in top layer must be B
  • Then the first two nodes in bottom layer must be F and T, resp.
  • Then no color left for the remaining node ⇒ contradiction!
slide-54
SLIDE 54

3-Coloring

373F19 - Nisarg Shah & Karan Singh 54

➢ We just proved: valid 3-coloring ⇒ satisfying assignment ➢ Claim: satisfying assignment ⇒ valid 3-coloring

  • Color all true literals as T and their negations as F
  • Valid 3-coloring for the literal widget
  • Each clause widget with at least one T literal can be 3-colored
slide-55
SLIDE 55

Review of Reductions

373F19 - Nisarg Shah & Karan Singh 55

  • If you want to show that problem B is NP-complete
  • Step 1: Show that B is in NP

➢ Some polynomial-size advice should be sufficient to verify

a YES instance in polynomial time

➢ No advice should work for a NO instance ➢ Usually, the solution of the “search version” of the

problem works

  • But sometimes, the advice can be non-trivial
  • For example, to check LP optimality, one possible advice is the

values of both primal and dual variables, as we saw in the last lecture

slide-56
SLIDE 56

Review of Reductions

373F19 - Nisarg Shah & Karan Singh 56

  • If you want to show that problem B is NP-complete
  • Step 2: Find a known NP-complete problem A and

reduce it to B (i.e. show A ≤𝑞 B)

➢ This means taking an arbitrary instance of A, and solving

it in polynomial time using an oracle for B

  • Caution 1: Remember the direction. You are “reducing known NP-

complete problem to your current problem”.

  • Caution 2: The size of the B-instance you construct should be

polynomial in the size of the original A-instance

➢ This would show that if B can be solved in polynomial

time, then A can be as well

➢ Some reductions are trivial, some are notoriously tricky…

slide-57
SLIDE 57

Integer Linear Programming (ILP)

373F19 - Nisarg Shah & Karan Singh 57

  • Problem

➢ Input: 𝑑 ∈ ℝ𝑜, 𝑐 ∈ ℝ𝑛, 𝐵 ∈ ℝ𝑛×𝑜, 𝑙 ∈ ℝ ➢ Question: Does there exist 𝑦 ∈ 0,1 𝑜 such that 𝑑𝑈𝑦 ≥ 𝑙

and 𝐵𝑦 ≤ 𝑐?

➢ Decision variant of “maximize 𝑑𝑈𝑦 subject to 𝐵𝑦 ≤ 𝑐” but

instead of any 𝑦 ∈ ℝ𝑜 with 𝑦 ≥ 0, we are restricting 𝑦 to binary.

➢ Does restricting search space make the problem easier or

harder?

  • This is actually NP-complete!
slide-58
SLIDE 58

IP Feasibility

373F19 - Nisarg Shah & Karan Singh 58

  • An even simpler problem

➢ Special case where 𝑑 = 𝑙 = 0, so 𝑑𝑈𝑦 ≥ 𝑙 is always true

  • Problem

➢ Input: 𝑐 ∈ ℝ𝑛, 𝐵 ∈ ℝ𝑛×𝑜 ➢ Question: Does there exist 𝑦 ∈ 0,1 𝑜 such that 𝐵𝑦 ≤ 𝑐? ➢ Just need to find a feasible solution ➢ This is still NP-complete!

slide-59
SLIDE 59
  • Claim: IP Feasibility is in NP

➢ Recall: We need to show that there is a polynomial-time

algorithm which

  • Can accept every YES instance with the right polynomial-size advice
  • Will not accept a NO instance with any advice

➢ Advice: simply a vector 𝑦 satisfying 𝐵𝑦 ≤ 𝑐

  • Algorithm: Check if 𝐵𝑦 ≤ 𝑐
  • Simple!

IP Feasibility

373F19 - Nisarg Shah & Karan Singh 59

slide-60
SLIDE 60
  • Claim: 3SAT ≤𝑞 IP Feasibility

➢ Take any formula 𝜒 of 3SAT ➢ Create a binary variable 𝑦𝑗 for each variable 𝑦𝑗 in 𝜒

  • We’ll represent its negation ҧ

𝑦𝑗 with 1 − 𝑦𝑗

➢ For each clause 𝐷, we want at least one of its three literals

to be TRUE

  • Just make sure their sum is at least 1
  • E.g. 𝐷 = 𝑦1 ∨ ҧ

𝑦2 ∨ ҧ 𝑦3 ⇒ 𝑦1 + 1 − 𝑦2 + 1 − 𝑦3 ≥ 1

➢ Easy to check that

  • this is a polynomial reduction
  • Resulting system has a feasible solution iff 𝜒 is satisfiable

IP Feasibility

373F19 - Nisarg Shah & Karan Singh 60

slide-61
SLIDE 61

So far…

373F19 - Nisarg Shah & Karan Singh 61

  • To establish NP-completeness of problem B, we

always reduced 3SAT to B

➢ But we can reduce any other problem A that we have

already established to be NP-complete

➢ Sometimes this might lead to a simpler reduction

because A might already be “similar” to B

  • Let’s see an example!
slide-62
SLIDE 62

Vertex Cover

373F19 - Nisarg Shah & Karan Singh 62

  • Problem

➢ Input: Undirected graph 𝐻 = (𝑊, 𝐹), integer 𝑙 ➢ Question: Does there exist a vertex cover of size 𝑙?

  • That is, does there exist 𝑇 ⊆ 𝑊 with 𝑇 = 𝑙 such that every edge is

incident to at least one vertex in 𝑇?

= vertex cover Example:

  • Does this graph have a

vertex cover of size 4?

  • Yes!
  • Does this graph have a

vertex cover of size 3?

  • No!
slide-63
SLIDE 63

Vertex Cover

373F19 - Nisarg Shah & Karan Singh 63

  • Problem

➢ Input: Undirected graph 𝐻 = (𝑊, 𝐹), integer 𝑙 ➢ Question: Does there exist a vertex cover of size 𝑙?

  • That is, does there exist 𝑇 ⊆ 𝑊 with 𝑇 = 𝑙 such that every edge is

incident to at least one vertex in 𝑇?

= independent set Question:

  • Did we see this graph in

the last lecture?

  • Yes!
  • For independent set
  • f size 6

= vertex cover

slide-64
SLIDE 64

Vertex Cover

373F19 - Nisarg Shah & Karan Singh 64

  • Vertex cover and independent set are intimately

connected!

  • Claim: 𝐻 has a vertex cover of size 𝑙 if and only if 𝐻

has an independent set of size 𝑜 − 𝑙

  • Stronger claim: 𝑇 is a vertex cover if and only if 𝑊\S is

an independent set

slide-65
SLIDE 65

Vertex Cover

373F19 - Nisarg Shah & Karan Singh 65

  • Claim: 𝑇 is a vertex cover if and only if 𝑊\S is an

independent set

  • Proof:

➢ 𝑇 is a vertex cover ➢ IFF: For every 𝑣, 𝑤 ∈ 𝐹, at least one of {𝑣, 𝑤} is in 𝑇 ➢ IFF: For every 𝑣, 𝑤 ∈ 𝐹, at most one of {𝑣, 𝑤} is in 𝑊\S ➢ IFF: No two vertices of 𝑊\S are connected by an edge ➢ IFF: 𝑊\S is an independent set ∎

slide-66
SLIDE 66

Vertex Cover

373F19 - Nisarg Shah & Karan Singh 66

  • Claim: Independent Set ≤𝑞 Vertex Cover

➢ Take an arbitrary instance (𝐻, 𝑙) of Independent Set ➢ We want to check if there is an independent set of size 𝑙 ➢ Just convert it to the instance (𝐻, 𝑜 − 𝑙) of Vertex Cover ➢ Simple!

  • A reduction from 3SAT would have basically repeated the reduction

we already did for 3SAT ≤𝑞 Independent Set

➢ Note: I didn’t argue that Vertex Cover is in NP

  • This is simple as usual. Just give the actual vertex cover as the advice.
slide-67
SLIDE 67

Set Cover

373F19 - Nisarg Shah & Karan Singh 67

  • Problem

➢ Input: A universe of elements 𝑉, a family of subsets 𝑇, and

an integer 𝑙

➢ Question: Do there exist 𝑙 sets from 𝑇 whose union is 𝑉?

  • Example

➢ 𝑉 = {1,2,3,4,5,6,7} ➢ 𝑇 =

1,3,7 , 2,4,6 , 4,5 , 1 , 1,2,6

➢ 𝑙 = 3? Yes! 1,3,7 , 4,5 , {1,2,6} ➢ 𝑙 = 2? No!

slide-68
SLIDE 68
  • Claim: Set Cover is in NP

➢ Easy. Let the advice be the actual 𝑙 sets whose union is 𝑉.

  • Claim: Vertex Cover ≤𝑞 Set Cover

➢ Given an instance of vertex cover with graph 𝐻 = (𝑊, 𝐹) and

integer 𝑙, create the following set cover instance

  • Set 𝑉 = 𝐹
  • For each 𝑤 ∈ 𝑊, 𝑇 contains a set 𝑇𝑤 of all edges incident on 𝑤
  • Selecting 𝑙 set whose union is 𝑉 = selecting 𝑙 vertices such that

union of their incident edges covers all edges

  • Hence, the two problems obviously have the same answer

Set Cover

373F19 - Nisarg Shah & Karan Singh 68

slide-69
SLIDE 69

373F19 - Nisarg Shah & Karan Singh 69

slide-70
SLIDE 70

Cook-Levin Theorem

373F19 - Nisarg Shah & Karan Singh 70

  • We did not prove “the first NP-completeness”

result

  • Theorem: 3SAT is NP-complete

➢ We need to prove this without using any other “known

NP-complete” problem

➢ We want to directly show that every problem in NP can

be reduced to 3SAT

slide-71
SLIDE 71

Cook-Levin Theorem

373F19 - Nisarg Shah & Karan Singh 71

  • We’re not going to prove it in this class, but the key

idea is as follows

➢ If a problem is in NP, then ∃ Turing machine 𝑈(𝑦, 𝑧) which ➢ …takes a problem instance 𝑦, an advice 𝑧 of 𝑞(𝑜) size,

and verifies in 𝑞(𝑜) time whether 𝑦 is a YES instance…

➢ …where 𝑞 is some polynomial and 𝑜 = |𝑦| ➢ 𝑦 is a YES instance iff ∃𝑧 𝑈 𝑦, 𝑧 = 𝐵𝐷𝐷𝐹𝑄𝑈

slide-72
SLIDE 72

Cook-Levin Theorem

373F19 - Nisarg Shah & Karan Singh 72

  • We’re not going to prove it in this class, but the key

idea is as follows

➢ 𝑦 is a YES instance iff ∃𝑧 𝑈 𝑦, 𝑧 = 𝐵𝐷𝐷𝐹𝑄𝑈 ➢ We can introduce a bunch of variables…

  • 𝑈

𝑗,𝑘,𝑙 = True if machine’s tape cell 𝑗 contains symbol 𝑘 at step 𝑙 of

the computation

  • 𝐼𝑗,𝑙 = True if the machine’s read/write head is at tape cell 𝑗 at step

𝑙 of the computation

  • 𝑅𝑟,𝑙 = True if machine is in state 𝑟 at step 𝑙 of the computation

➢ Then express how these variables must be related using a

bunch of constraints (clauses)

  • This shows SAT is NP-complete. Then we can show SAT ≤𝑞 3SAT.
slide-73
SLIDE 73

Cook-Levin Theorem

373F19 - Nisarg Shah & Karan Singh 73

  • Claim: SAT ≤𝑞 3SAT

➢ Given an instance 𝜒 = 𝐷1 ∧ 𝐷2 ∧ ⋯ of SAT, we can take

each clause, and replace it with a bunch of clauses with exactly 3 literals each

  • For a clause with one literal 𝐷 = ℓ1:
  • Add two variables 𝑨1, 𝑨2, and replace it with four clauses

ℓ1 ∨ 𝑨1 ∨ 𝑨2 ∧ ℓ1 ∨ ҧ 𝑨1 ∨ 𝑨2 ∧ ℓ1 ∨ 𝑨1 ∨ ҧ 𝑨2 ∧ ℓ1 ∨ ҧ 𝑨1 ∨ ҧ 𝑨2

  • Verify that this is indeed always equal to ℓ1
  • For a clause with two literals 𝐷 = (ℓ1 ∨ ℓ2):
  • Add one variable 𝑨1 and replace it with the following:

ℓ1 ∨ ℓ2 ∨ 𝑨1 ∧ ℓ1 ∨ ℓ2 ∨ ҧ 𝑨1

  • Verify that this is indeed logically equal to ℓ1 ∨ ℓ2
slide-74
SLIDE 74

Cook-Levin Theorem

373F19 - Nisarg Shah & Karan Singh 74

  • Claim: SAT ≤𝑞 3SAT
  • For a clause with three literals 𝐷 = ℓ1 ∨ ℓ2 ∨ ℓ3:
  • Perfect. No need to do anything!
  • For a clause with 4 or more literals 𝐷 = (ℓ1 ∨ ℓ2 ∨ ⋯ ∨ ℓ𝑙):
  • Add variables 𝑨1, 𝑨2, … , 𝑨𝑙−3 and replace it with:

ℓ1 ∨ ℓ2 ∨ 𝑨1 ∧ ℓ3 ∨ ҧ 𝑨1 ∨ 𝑨2 ∧ ℓ4 ∨ ҧ 𝑨2 ∨ 𝑨3 ∧ ⋯ ∧ ℓ𝑙−2 ∨ ҧ 𝑨𝑙−4 ∨ 𝑨𝑙−3 ∧ ℓ𝑙−1 ∨ ℓ𝑙 ∨ ҧ 𝑨𝑙−3

  • If one of the ℓ’s is TRUE, you can make this TRUE by setting

appropriate values for 𝑨 variables (check!)

  • If all ℓ are FALSE, then there is no way to make the above

conjunction TRUE (check!)

slide-75
SLIDE 75

NP vs co-NP

373F19 - Nisarg Shah & Karan Singh 75

  • Complements of each other

➢ NP = short proof for YES, co-NP = short proof for NO ➢ If a problem “Does there exist…” is in NP, then its

complement “Does there not exist…” is in co-NP, and vice-versa

➢ The same goes for NP-complete and co-NP-complete

  • Example

➢ SAT is NP-complete (“Does there exist 𝑦 satisfying 𝜒?”) ➢ Tautology is coNP-complete (“Does there exist no 𝑦

satisfying 𝜒?” = “Is 𝜒 always FALSE?”)

slide-76
SLIDE 76

NP ∩ co-NP

373F19 - Nisarg Shah & Karan Singh 76

  • Clearly, P ⊆ NP ∩ co-NP

➢ No advice needed; can just solve the problem in polytime ➢ Major open question: Is P = NP ∩ co-NP?

  • How about a short proof of both YES and NO?

➢ Hunt for problems not known in P but still in NP ∩ co-NP

slide-77
SLIDE 77

NP ∩ co-NP

373F19 - Nisarg Shah & Karan Singh 77

  • Linear programming

➢ [Gale–Kuhn–Tucker 1948]: LP is in NP ∩ co-NP

slide-78
SLIDE 78

NP ∩ co-NP

373F19 - Nisarg Shah & Karan Singh 78

  • Linear programming

➢ But later, we found out: ➢ [Khachiyan 1979]: LP is in P

slide-79
SLIDE 79

NP ∩ co-NP

373F19 - Nisarg Shah & Karan Singh 79

  • Primality testing (“Is 𝑜 a prime?”)

➢ [Pratt 1975]: PRIMES is in NP ∩ co-NP

  • A short NO proof is easy, but a short YES proof relies on some

interesting math

slide-80
SLIDE 80

NP ∩ co-NP

373F19 - Nisarg Shah & Karan Singh 80

  • Primality testing (“Is 𝑜 a prime?”)

➢ But later we found out: ➢ [Agrawal–Kayal–Saxena 2004]: PRIMES is in P

  • Milestone result!
slide-81
SLIDE 81

NP ∩ co-NP

373F19 - Nisarg Shah & Karan Singh 81

  • Factoring (“Does 𝑜 have a factor ≤ 𝑙?”)

➢ FACTOR is in NP ∩ co-NP

  • Short YES proof: Just present the factor
  • Short NO proof:
  • Present the entire prime factorization of 𝑜, along with a short

proof that each presented factor is a prime

  • A TM can check that each factor is a prime
  • Actually, proofs of primality are not required now that we

know the TM can just run AKS algorithm to check primality

  • The TM can also verify that none of the factors is ≤ 𝑙
slide-82
SLIDE 82

NP ∩ co-NP

373F19 - Nisarg Shah & Karan Singh 82

  • Factoring (“Does 𝑜 have a factor ≤ 𝑙?”)

➢ Major open question: Is FACTOR in P?

  • Basis of several cryptographic procedures

➢ Challenge: Factor the following number.

74037563479561712828046796097429573142593188889231289 08493623263897276503402826627689199641962511784399589 43305021275853701189680982867331732731089309005525051 16877063299072396380786710086096962537934650563796359 RSA-704 ($30,000 prize if you can factor it)

slide-83
SLIDE 83

NP ∩ co-NP

373F19 - Nisarg Shah & Karan Singh 83

  • Factoring (“Does 𝑜 have a factor ≤ 𝑙?”)

➢ [Shor 1994]: We can factor an 𝑜-bit integer in 𝑃(𝑜3)

steps on a quantum computer.

➢ *Scalable* quantum computers can help

  • 2001: Factored 15 = 3 x 5 (with high probability)
  • 2012: Factored 21 = 3 x 7
slide-84
SLIDE 84

Other Complexity Classes

373F19 - Nisarg Shah & Karan Singh 84

  • Based on the exact time complexity

➢ DTIME(𝑜), NTIME(𝑜2), …

  • Deterministic / nondeterministic time complexity
  • Based on space complexity

➢ DSPACE(𝑜), NSPACE(log 𝑜)

  • Using randomization

➢ ZPP (expected polytime, no errors)

  • Allowing probabilistic errors

➢ RP (polytime, one-sided error) ➢ BPP (polytime, two-sided erros)