Lecture 20

Today:

    1. Analysis of algorithms.

    2. Dynamic programming.

    3. P and NP

For next time:

    1. Finish Homework 10.

    2. Reading questions below.

    3. Prepare for a quiz.

Analysis of Algorithms

Instead of Sipser's Section 7.1, let's read Think Complexity, Chapter 3, just the first two sections.

Do Exercise 1.

Dynamic programming

Write a Python function that evaluates F, where F(0)=1, F(1)=1, and F(n) = F(n-1) + F(n-2).

Start with a naive recursive version. What is the run time of this algorithm as a function of n?

How many times does it evaluate F(0)?

Dynamic programming is a general technique for improving algorithms like this "exhibiting (1) the properties of overlapping subproblems which are only slightly smaller, and (2) optimal substructure [Wikipedia]"

Here's a way to sneak up on dynamic programming:

1) Write a recursive version of your function using a global list or dictiory to store previously-computed results. This technique is called "memoization".

2) Make a sequence of function calls to preload the cache. This limits the depth of the call stack.

3) Consider optimizing the data structure you use to store the cached results.

Reading questions

Sipser, pages 270-283.

1) Why is NP-completeness a useful concept?

2) If A is poly-time reducible to B, does that mean that if we can solve A in poly-time, then we can solve B in poly-time?

3) If 3SAT is poly-time reducible to CLIQUE, what does the function f(w) take as a parameter and what does it produce?

4) What are the two requirements for NP-completeness?

5) What's the hard way to prove that a problem is NP-complete? What's the easy (ok, easier :) way?

6) What do the rows of a tableau represent? What is an "accepting" tableau? What does it mean if there is an accepting tableau for machine N and input w?

7) If any NP machine can be reduced to SAT, what does the function f take as a parameter and what does it return?

8) What are the requirements of a legal tableau?

9) How does the generated formula (phi) check that the tableau is accepting?

10) Do exercise 7.5 on page 294, "Is the following formula satisfiable?"

11) Do exercise 7.6 on page 294, "Show that P is closed..."

12) Do problem 7.15 on page 295, "Show that NP is closed..." [Feel free to read the answer, but think about it first!]