**CS344 - 01:198:344 - Design and Analysis of Computer Algorithms (4 Cr.)**

**Spring 2012**

Professor Mario Szegedy

MW 6:40-8:00PM ARC-107 Busch

Section 01: M 5:15-6:10PM HLL-005 Busch

Section 02: W 3:35-4:30PM HLL-005 Busch

Professor Mario Szegedy

Tarek El-Gaaly

Next to the Busch Campus Center. For directions, see: Map

My cubicle is the farthest one to the back on the left as you come in.

Xiang Yu

Next to the Busch Campus Center. For directions, see: Map

My cubicle is the towards the left as you come in.

In chronological order from oldest to most recent. Red announcements are new.

Starting with the next class the instructor will pass around an attendance record sheet in the first five minute of every class. The sheet will be used to ask questions from the students present.

Homework 1 Posted below

Fast Fourier:

I see I was a little quick with the FFT. As is, it would devastate you in the exam, so I will see what we can do. In any case, matrix operations, arithmetic complexiity (number of arithmetic operations) are a must to know. Try to catch up with them (you need them for one of the homeworks, anyway). We shall also hover over them (and FFT) in the next class before going on. Stay tuned. MS

Study Guide by Chapter:

Chapter 0: All topics. Review again the homework exercises. Additional exercises:

1. The left side is O, o, Omega, omega or theta of the right side?

(log n)^(log n) vs n^(log log n)

3^(2n) vs 2^(3n)

n^10 * log n vs n^9 * (log n)^10

n/log n vs sqrt(n) * log n

3^(3^n) vs n^(n^3)

sum_{1< i < n} i^3 vs n^5 - 50n

n choose sqrt(n) vs sqrt(n) factorial

2. Is it true that if the average case complexity of a problem is O(n), then the worst case complexity is at most O(n^2)?

3. Design a (deterministic) linear time algorithm for finding the third smallest element in an array

4. Design an average case linear time algorithm for outputting an ordered list of the smallest n/logn elements of an array of length n

5. Create a problem and solve it :)

Chapter 1:

All topics. Review again the homework exercises. Additional exercises:

1. Solve from the book: 1.6 - 1.18; 1.33 - 1.36; 1.38; 1.43; 1.44 is very cool. I had to think on it for three minutes.

2. Determine x^100 modulo x+1. (polynomial modulus)

3. Determine the gcd of x^100 and x^2 + 1. Determine the gcd of x^100 + 1 and x^2 + 1. Determine the gcd of x^200 + x^100 and x^2 + 1.

Chapter 2:

All topics except 2.61, 2.62, 2.63. The "FFT unraveled" part in the end is also left out. Review again the homework exercises. Additional exercises:

1. Exercises 2.5, 2.14, 2.22, 2.23, 2.26 (help: reduce the multiplication problem to squaring), 2.28 (We have done this in class), 2.32

2. Which has a bigger solution? F(n) = 57 F(n/57) + O(n) or F(n) = 157 F(n/157) + O(n) ?

3. Let M be the n by n matrix that has 1s in the main diagonal and above, and zero below the main diagonal. How fast can you multiply M with an input vector v?

Chapter 3:

Up to section 3.2.3 (3.2.3 included). But no pre and post numbers (like in Figure 3.6). Exercises:

1. 3.1 from book.

2. Give a graph whose DFS tree (no matter how you number the nodes) is a path.

Notes on big-O versus little-o can be found under the slides section

Also, the practice exam and solutions can be found there too

Slides slides

STUDY GUIDE FOR MIDTERM II

I will clone the problems for Mid2 (foreseeably 4-6 problems) from the following list of problems in the book. The clones will not be identical twins of the problems in the book, but please bring your book to the exam, because there could be references to its pages. For your convenience I classified the problems according to the aspects along which I plan to clone them. Any problem in Mid2 will belong to the one of the following 11 categories:

I. Run a known algorithm on some given input instance and (possibly) answer simple questions about the instance or the algorithm. There will be at least one such problem on the exam (maybe two):

3.2 3.3 3.4 4.1 4.2 5.1 5.2

II. Find the right algorithm (among the ones you have learned) for a problem, and give an explanation of how you want to apply it in the given situation:

3.8

III. Prove some simple facts about graphs:

3.6 5.4 5.10

IV. Solve a very simple task in linear (or nearly linear time). For the solution you do not necessarily need to apply any algorithm you have learned about:

3.5 3.9 5.3

V. [my favorite type] Design an algorithm for a problem, where the solution requires applying a known algorithm in clever ways, or it requires modifying a known algorithm. (sometimes both types of solution exist, sometimes only one):

3.11 3.22 3.24 4.3 4.14 4.15 4.20 5.7

VI. Make simple observations about known algorithms:

3.12

VII. Writing useful previsit(), postvisit() routines for explore/DFS

3.25

VIII. Understand equivalence relations

3.29 3.31

IX. Problems that require ingenuity

3.23 4.5 4.7 4.11 4.17

X. Do modification of known algorithms work? Do they work on select illegal inputs? If not, why not.

4.8 4.9

Xi. Construct worst case input for known algorithms:

5.12

**Course Description **

Electronic version:

http://www.cs.berkeley.edu/~vazirani/algorithms.html

We go through the Dasgupta, Papapimitriou, Vazirani book chapter by chapter, leaving out the Linear Programming and quantum computing chapters.

**Homeworks**

problems: 01, 02, 04a, b from the book

due date: Thursday, January 26 @ 12pm

problems: Book: 1.18, 1.20, 1.26

due date: Thursday, Feb 2nd @ 12pm

problems: Two of the three homework exercises are from the book: 1.19 (Fibonacci) 1.28 (RSA)

The third exercise is related to the Extended Euclidean Algorithm for polynomials:

Show that two polynomials, P and Q the gcd of P(x^3) and Q(x^3) is also a polynomial of x^3, i.e. of the form R(x^3).

Warm up question 1: For P = x^2 + x + 1 what is P(x^3)?

Warm up question 2: What is the gcd of x^6 - 1 and x^9 - 1?

due date: Thursday, Feb 9th @ 12pm

1. Book, 1.31

2. Book, 2.19

3. Compute and argue which is bigger (T(n) or G(n)):

T(n) = 6T(n/2) + n^2

G(n) = 9T(n/3) + sqrt(n^5)

show your work.

due Feb 16th @ noon

1. Book, 2.7

2. Book, 2.11

3. Book, 2.15

due Feb 23rd @ noon

Exercises 3.3 and 3.4 from the book.

Due date: March 22nd @ 11:55pm.

In the Monday lecture we will cover the strongly connected component algorithm

1. Let G be a directed graph on n nodes. Assume that its meta-graph has k edges, and its number of strongly connected components with size 1 is s. Prove that that G must have at least n+k-s edges.

(n is the number of nodes and k is the number of edges in the meta-graph)

2. Solve 3.22 from the book. Give a sample run of your algorithm on the graph drawn for exercise 3.25 (you do not need the rest of the exercise itself, only the picture of the graph).

due date: Thursday, March 29th @11:55pm

1. Let G be a DAG. Assume that we topologically sort the nodes of G, and then relabel them accordingly (thus the node that is first in the topological order gets label 1, the next gets label 2,etc., and the last gets label n).

Let P be a directed path in G. Prove or disprove the following statement: If we run the BFS on G using these new labels, then the BFS will discover the edges of P in the order in which the occur in P (that is, the BFS will discovers the first edge of P before discovering any other edge of P, etc.)

2. What if we replace BFS with DFS in the above problem (keeping the rest the same)?

due date: Thursday, April 5th @11:55pm

1. The homework for the next week is exercise 5.1 (a) (b) (c) from the book, and in addition:

2. Construct the minimum weight spanning tree (and compute its total cost) of the graph to exercise 5.1 when the weights are modified as follows:

a.) the weights are the squares of the weights given by the book (3 -> 9, etc.)

b.) the weights are negatives of the weights given by the book (3 -> -3, etc.)

3. Which two of the three trees you have constructed (when you disregard the weights) are identical and why?

Definition: total cost = sum of the weights on the edges of the spanning tree.

due date: Thursday, April 12th @11:55pm

In a linguistic conference Dr Joseph Smith has recommended a measure for the distance between two words, v and w, as follows:

We associate a cost measure to any letter-alteration as folows:

If a vowel is deleted, it costs 3 (boat -> bat)

If a vowel is inserted, it costs 3 (hill -> hilal)

If a vowel is changed to another vowel, it costs 2 (hot -> hit)

If a consonant is deleted, it costs 2 (trace -> race)

If a consonant is inserted, it costs 2 (rain -> ratin)

If a consonant is changed to another consonant, it costs 1 (shore -> snore)

(a consonant cannot be changed to a vowel or vice versa)

Any word can be changed into any other by performing a sequence of alterations, where every alteration comes from the above list.

The total cost of an alteration-sequence is the sum of the costs of the individual alterations in the sequence.The distance between v and w is minimum total cost that incurs when we alter v to w,

(trace -> race -> bace -> bac -> bat ) costs 2+ 1 + 3 + 1=7. Can you do it cheaper? (no) The distance between "trace" and "bat" is 7.

Design a dynamic programming algorithm for Dr J.S. that takes v and w as it input, and computes the distance between the two words.

due date: Thursday April, 26th @11:55pm