BU CS 332 Theory of Computation Lecture 22: Reading: NP - - PowerPoint PPT Presentation

bu cs 332 theory of computation
SMART_READER_LITE
LIVE PREVIEW

BU CS 332 Theory of Computation Lecture 22: Reading: NP - - PowerPoint PPT Presentation

BU CS 332 Theory of Computation Lecture 22: Reading: NP Completeness Example Sipser Ch 8.1 8.2 Space Complexity Savitchs Theorem Mark Bun April 22, 2020 NP completeness Definition: A language is NP complete if 1)


slide-1
SLIDE 1

BU CS 332 – Theory of Computation

Lecture 22:

  • NP‐Completeness Example
  • Space Complexity
  • Savitch’s Theorem

Reading: Sipser Ch 8.1‐8.2

Mark Bun April 22, 2020

slide-2
SLIDE 2

NP‐completeness

Definition: A language is NP‐complete if 1) and 2) Every language is poly‐time reducible to , i.e.,

  • (“

is NP‐hard”) Theorem: If and

  • for some NP‐complete

language , then is also NP‐complete

4/22/2020 CS332 ‐ Theory of Computation 2

slide-3
SLIDE 3

(3‐CNF Satisfiability)

Definition(s):

  • A literal either a variable of its negation

,

  • A clause is a disjunction (OR) of literals

Ex.

  • A 3‐CNF is a conjunction (AND) of clauses where each

clause contains exactly 3 literals Ex.

  • Cook‐Levin Theorem:

is NP‐complete

4/22/2020 CS332 ‐ Theory of Computation 3

slide-4
SLIDE 4

4/22/2020 CS332 ‐ Theory of Computation 4

slide-5
SLIDE 5

Some general reduction strategies

  • Reduction by simple equivalence
  • Ex. 𝐽𝑂𝐸𝐹𝑄𝐹𝑂𝐸𝐹𝑂𝑈 𝑇𝐹𝑈 𝑊𝐹𝑆𝑈𝐹𝑌 𝐷𝑃𝑊𝐹𝑆

and 𝑊𝐹𝑆𝑈𝐹𝑌 𝐷𝑃𝑊𝐹𝑆 𝐽𝑂𝐸𝐹𝑄𝐹𝑂𝐸𝐹𝑂𝑈 𝑇𝐹𝑈

  • Reduction from special case to general case
  • Ex. 𝑊𝐹𝑆𝑈𝐹𝑌 𝐷𝑃𝑊𝐹𝑆 𝑇𝐹𝑈 𝐷𝑃𝑊𝐹𝑆
  • Gadget reductions
  • Ex. 3𝑇𝐵𝑈 𝐽𝑂𝐸𝐹𝑄𝐹𝑂𝐸𝐹𝑂𝑈 𝑇𝐹𝑈

4/22/2020 CS332 ‐ Theory of Computation 5

slide-6
SLIDE 6

Independent Set

4/22/2020 CS332 ‐ Theory of Computation 6

An independent set in an undirected graph 𝐻 is a set of vertices that includes at most one endpoint of every edge.

𝐽𝑂𝐸𝐹𝑄𝐹𝑂𝐸𝐹𝑂𝑈 𝑇𝐹𝑈

  • 𝐻, 𝑙 𝐻 is an undirected graph containing an independent set with 𝑙 vertices
  • Is there an independent set of size  6?
  • Yes.
  • Is there an independent set of size  7?
  • No.

independent set

slide-7
SLIDE 7

Independent Set is NP‐complete

1) 2) Reduce

  • Proof. “On input 𝜒 , where 𝜒 is a 3CNF formula,
  • 1. Construct graph 𝐻 from 𝜒
  • 𝐻 contains 3 vertices for each clause, one for each literal.
  • Connect 3 literals in a clause in a triangle.
  • Connect literal to each of its negations.

2. Output 𝐻, 𝑙 , where 𝑙 is the number of clauses in 𝜒.”

4/22/2020 CS332 ‐ Theory of Computation 7

slide-8
SLIDE 8

Example of the reduction

4/22/2020 CS332 ‐ Theory of Computation 8

𝜒 𝑦 ∨ 𝑦 ∨ 𝑦 ∧ 𝑦 ∨ 𝑦 ∨ 𝑦 ∧ 𝑦 ∨ 𝑦 ∨ 𝑦

slide-9
SLIDE 9

Proof of correctness for reduction

Let 𝑙 = # clauses and 𝑚 = # literals in 𝜒 Claim: 𝜒 is satisfiable iff 𝐻 has an ind. set of size 𝑙 ⟹ Given a satisfying assignment, select one literal from each

  • triangle. This is an ind. set of size 𝑙

⟸ Let 𝑇 be an ind. set of size 𝑙

  • 𝑇 must contain exactly one vertex in each triangle
  • Set these literals to true, and set all other variables in an arbitrary

way

  • Truth assignment is consistent and all clauses satisfied

Runtime: 𝑃𝑙 𝑚 which is polynomial in input size

4/22/2020 CS332 ‐ Theory of Computation 9

slide-10
SLIDE 10

Space Complexity

4/22/2020 CS332 ‐ Theory of Computation 10

slide-11
SLIDE 11

Complexity measures we’ve studied so far

  • Deterministic time TIME
  • Nondeterministic time NTIME
  • Classes P, NP

Many other resources of interest: Space (memory), randomness, parallel runtime / #processors, quantum entanglement, interaction, communication, …

4/22/2020 CS332 ‐ Theory of Computation 11

slide-12
SLIDE 12

Space analysis

Space complexity of a TM (algorithm) = maximum number

  • f tape cell it uses on a worst‐case input

Formally: Let . A TM runs in space if on every input

∗,

halts on using at most cells For nondeterministic machines: Let . An NTM runs in space if on every input

∗,

halts on using at most cells on every computational branch

4/22/2020 CS332 ‐ Theory of Computation 12

slide-13
SLIDE 13

Space complexity classes

Let A language if there exists a basic single‐ tape (deterministic) TM that 1) Decides , and 2) Runs in space A language if there exists a single‐ tape nondeterministic TM that 1) Decides , and 2) Runs in space

4/22/2020 CS332 ‐ Theory of Computation 13

slide-14
SLIDE 14

Example: Space complexity of SAT

Theorem: Proof: The following deterministic TM decides using linear space On input where is a Boolean formula:

  • 1. For each truth assignment to the variables
  • f :

2. Evaluate

  • n
  • 3. If any evaluation

, accept. Else, reject.

4/22/2020 CS332 ‐ Theory of Computation 14

slide-15
SLIDE 15

Example: NFA analysis

Theorem: Let

Then

  • .

Proof: The following NTM decides

in linear space

On input where is an NTM: 1. Place a marker on the start state of . 2. Repeat times where is the # of states of : 3. Nondeterministically select . 4. Adjust the markers to simulate all ways for to read 5. Accept if at any point none of the markers are on an accept

  • state. Else, reject.

4/22/2020 CS332 ‐ Theory of Computation 15

slide-16
SLIDE 16

Example

4/22/2020 CS332 ‐ Theory of Computation 16

0,1 ε 2 3 1 1

slide-17
SLIDE 17

Space vs. Time

4/22/2020 CS332 ‐ Theory of Computation 17

slide-18
SLIDE 18

Space vs. Time

How about the opposite direction? Can low‐space algorithms be simulated by low‐time algorithms?

4/22/2020 CS332 ‐ Theory of Computation 18

slide-19
SLIDE 19

Reminder: Configurations

4/22/2020 CS332 ‐ Theory of Computation 19

A configuration is a string where and

  • Tape contents =

(followed by blanks )

  • Current state =
  • Tape head on first symbol of

Example:

  • Start configuration:

Accepting configuration: = Rejecting configuration: =

slide-20
SLIDE 20

Reminder: Configurations

4/22/2020 CS332 ‐ Theory of Computation 20

Consider a TM with

  • states
  • tape alphabet
  • space

How many configurations are possible when this TM is run on an input

  • Observation: If a TM enters the same configuration twice

when run on input it loops forever Corollary: A TM running in space also runs in time

slide-21
SLIDE 21

Savitch’s Theorem

4/22/2020 CS332 ‐ Theory of Computation 21

slide-22
SLIDE 22

Savitch’s Theorem: Deterministic vs. Nondeterministic Space

Theorem: Let be a function with . Then

  • 4/22/2020

CS332 ‐ Theory of Computation 22