CMPSCI 311: Theory of Algorithms

David Mix Barrington

Fall, 2003

Here are questions and answers on HW#6, due 31 October 2003. Questions are in black, answers in blue.

Question 5, 30 October 2003

For the first problem, I'm unclear on the general concept of "proving an algorithm correct". Can you help?

The statement that the algorithm gets the right answer on all input is a mathematical statement that is proved like other mathematical statements. For example, if it can be stated in terms of quantifiers, you use CMPSCI-250 proving-things-with-quantifiers methods to prove it.

For example, "being sorted" means "for all x, for all y, x is less than y iff x is before y". So you prove this by letting x and y be arbitrary and arguing that the condition "x is less than y iff x is before y" is true for those x and y.

For recursive algorithms in particular, you want to use induction. You assume that the algorithm is correct for the recursive call, and use this assumption to prove that it is correct overall.

In this case the Johnson-Trotter algorithm is not explicitly recursive but you want to argue as though it were. (Note that when Levitin begins to describe it in 5.4 he talks as though it were recursive.) Your inductive hypothesis might be "on input n, the J-T algorithm generates all permutations of n objects" and your inductive goal is "on input n+1, it generates all permutations of n+1 objects". In order to use the IH to prove the IG, you will need to argue that some of the time, the n+1 J-T algorithm is doing exactly what the n J-T algorithm would be doing.

Question 4, 30 October 2003

On question 6.3.2 (b), you ask us to also prove the result from class characterizing N(h) in terms of fibonacci numbers. I have the notes from class, but I don't seem to understand all the steps in getting to our connection between the number of nodes in the smallest possible AVL tree of depth n and the fibonacci numbers.

I understand the recursive definition of N(h) = N(h-1) + N(h-2) + 1. [argument why this is true]

It's also clear to me, experimentally, that the size of N(h) (given the base cases N(1) = 2 and N(2) = 2) is identical to N(h-1) + Fib(h) (aka the difference between any two elements, h and h-1, is the h-th fibonacci number).

You can go further with this and characterize N itself in terms of fibonacci numbers.

What survives in my notes for the last bit is scribblings of a bunch of kindof-equalities that I don't really understand. Where do I go from here in approaching the proof that connects the tree of minimal nodes for a height h to the fibonacci numers? It would also be helpful for me if you could clearly state again what our "result from class" was.

There is a characterization of N(h) as something like Fib(h+a) + b, where a and b are constants. You need to find the values of a and b, then show that this N(h) is the unique function that satisfies the recurrence and the base case.

Also, for question 6.4.5, the book asks us to "determine its efficiency." Does that mean worst-case, best-case, average-case, or all three? In otherwords, how detailed of an analysis do you want for that?

Normally "efficiency" means "worst-case efficiency" though if you have anything to say about the others you're welcome to. Remember that to get a Theta(f) answer for "the efficiency of your algorithm" you have to show that there is some input causing it to take time Omega(f).

Question 3, 30 October 2003

I have a question about problem 6.2.10 a) where it asks to solve the system in 6.1.1 using Cramer's Rule. I am having difficulty understanding the notation that the author uses to describe the rule. Are x1..xj the solutions to the system?

The system is Ax = b, where A is an n by n matrix, and x and b are column vectors. So x = [x_1,...,x_n] is the solution to the system, yes.

And what are A1 and b? ("where detAj is the determinant of the matrix obtained by replacing the jth column of A by the column b," also, what is the jth column?).

The "j'th column of A" are the elements [a_{1,j}, a_{2,j}, ..., a_{n,j}]. The "column b" is the column vector with values [b_1,...,b_n]. I'm not sure about "A1" because I don't have my book right here, but Cramer's rule says "x_j is det(A_j)/det(A)". You can certainly find many other descriptions of Cramer's Rule on the web by googling.

So the matrix A_j has most of its elements the same as the elements of A, except that a_{1,j} is replaced by b_1, a_{2,j} by b_2, ..., and a_{n,j} by b_n.

Question 2, 27 October 2003

In q 6.3.7.b) we are supposed to give the largest number of compares, and the average number. My first approach was to just do my own counts, and average them and find worst. Then I wondered if we are supposed to do something more mathematical. I could visualize doing largest, but average for our specific tree using a mathematical is not clear to me how I would do that.

This is a specific question about a specific tree, so you need to do the count for each of the nine possible queries and average the answers.

Question 1, 22 October 2003

Despite taking some 9-10 math courses and all the CS courses I have taken, I have not come across long division with polynomials. This makes it hard to answer 6.5.5. Is there some source, etc that describes the process?

I got several web hits googling "long division polynomials" -- start there and let me know if you need more.

Last modified 30 October 2003