Chapter 34 Answers

Document last modified: 

Introduction

Question 1 How can you prove the difference between a program in an infinite loop or just taking a long time? Cannot.

Question 2

MatrixMultiplication( A[n,n], B[n,n], C[n,n])

for i ←1 to n do

for j ← 1 to n do

C[i,j] ←0

for k ← 1 to n do

C[i,j] ← C[i,j]+A[i,k]*B[k,j]

Question 3

            1-8
<5       /    \
       1-4    5-8
<3   / \ <7 /  \
  1-2  3-4 5-6 7-8
  / \    /\    /\   /\
1   2  3 4  5 6 7 8

Example: Nondeterministic graph coloring

Use 4 colors to color 5 vertices with all adjacent vertices a different color.

Question 4

Reductions

Question 5

  1. What is the complexity of B? Polynomial.
  2. What is the complexity of A? We don't specify. If we can reduce A → B then A is polynomial.
  3. What is α? What is A(α)? The input to A. An instance of A.
  4. What is β? What is B(β)? The input to B after reducing α. An instance of B.
  5. What is the work of the reduction algorithm in this case? Reducing α to b.

The First NP-Complete Problem

Question 6 To develop some intuition on determinism and NP-completeness, do the following on Figure (b) below:

  1. How would you solve for one output solution for x1, x2 and x3?

    for x1= 0 to 1
        for x2= 0 to 1
            for x3= 0 to 1
               if ((¬x3∧ x1∧ x2)∨¬x3)∧ ((x1∨x2)∨¬x3)∧ (¬x3∧ x1∧ x2) return ( x1, x2, x3)

     

  2. Try to guess and verify one solution for x1, x2 and x3. Your guess is nondeterministic but the verification is deterministic.

    Guess x1, x2 and x3 (all true) yields true by plugging in boolean values into expression.

  3. What is the worst-case complexity in determining the input to produce an output of 1? O(2n) for n variables.
     
  4. What is the complexity in verifying a given input produces an output of 1?  Consider the number of operations (gates) that must be evaluated. Θ(n) for n operations (gates), can assume same time for And, Or and Not operation regardless of input number.

 

Polynomial Time 34.1

Abstract Problems

Question: Give another (ij, sk) ∈ SPAP. ij=(G, y, x), sk=<y, z, x>

Formal Language Framework

Question: What is {0, 1}*? You can think of this in terms of EBNF from programming languages. {ε, 0, 1, 00, 01, 10, 11, 000, ... }

Lodd = {1, 11, 101, 111, 1001, ...}

* = {ε, 0, 1, 00, 01, 10, 11, 000, ... }

Question: What is Lodd? {ε, 0, 00, 10, 000, ... }

Question: What is L12 for L1 = {0, 1}?{00, 01, 10, 11}

 

Decision problem Q

Question:

Relation Between Decision Problems and Algorithms

Question a

For the instance of PATHL:

V= {s,y,z,x}

E = {(s,x),(x,y),(y,x),(y,z),(s,y)}

G = (V,  E)

Would APATH <G, s, x, 2>

  • accept?
  • reject?
  • decide?

Question b

What about APATH <G, s, x, 4>

34.2 Polynomial time verification

Algorithm's that verify membership in a language

Question: Are there problems where no known polynomial time algorithm exists to compute the solution, but a solution can be verified in polynomial time? 

Yes, HAM-CYCLE ∈ NP, but no known polynomial time algorithm exists to decide HAM-CYCLE.

Give another. Remember Circuit-Satisfiability has exponential (2n) complexity yet we can easily verify in polynomial time:

((¬x3∧ x1∧ x2)∨¬x3)∧ ((x1∨x2)∨¬x3)∧ (¬x3∧ x1∧ x2)

34.3 NP-Completeness and Reducibility

Reducibility - tool for proving languages belong to class P

Example

A1 decides Hamiltonian cycle visits each vertex exactly once.

L1 language of Hamiltonian cycle instances.

Example: A1( G )

A2 decides k-cycle is a cycle of length exactly k unique vertices.

L2 language of exactly k unique vertices cycle length instances.

Example: A2( G, 5 )

For a graph with v vertices:

we can answer the question: does a Hamiltonian cycle exist?

           with the question: does a cycle of length v exist?

The answer to both questions is the same.

Question
  1. What is x? G
  2. What is L2? L1, k
  3. What is A1(x)? 1
  4. What is f(x)? G, 5
  5. What is A2( f(x) )? 1
  6. What is the work of the reduction algorithm F in this case? Generate f, a function that inputs G and outputs G, 5.
  7. L1p L2? Yes.
  8. L2p L1? Yes. f-1((G,5))=G

V= {1,2,3,4,5}

E = {(1,2),(2,1),(1,5),(5,1),...}

G = (V,  E)

Question: What does the lemma imply about L1 if L1p L2? L2 ∈ P implies L1 ∈ P, if we have a polynomial time algorithm deciding L2 we have a polynomial time algorithm deciding L1 also.

NP-completeness

 

34.4 NP-completeness proofs