i CMPSCI 311 Q&A on HW#1, Fall 2003

CMPSCI 311: Theory of Algorithms

David Mix Barrington

Fall, 2003

Here are questions and answers on HW#1, due 12 September 2003. Questions are in black, answers in blue.

Question 6, 11 September 2003

I don't understand what is being asked for in 2.1.6 -- what is meant by "any sorting algorithm"?

Imagine that you have been given a "sort" method for arrays of Comparables but you can't see how it works. You want to write a method that may call this mystery sorter, such that your method (a) sorts all lists correctly, assuming that the mystery sorter is correct, (b) uses only n-1 comparisons in the best case. It should be clear that in the best case, your method must not call the mystery sorter, as you have no clue how many comparisons it might use.

For what input do most sorting algorithms do the least work? How would you tell whether you have this kind of input or not?

Question 5, 11 September 2003

In 1.2.2, may two people cross the bridge simultaneously from different ends?

No, because every crossing must include the flashlight and there is only one flashlight that can be in only one place at a time. If you are having trouble with this problem, you may want to model it by a weighted graph. This graph would have 32 nodes, one for each subset of the five-element set (consisting of the four people and the flashlight) on a given side of the bridge. A successful crossing strategy would be a directed path in this graph, and the time taken would be the length of the path. So you want to find a path from the start to the finish node of length at most 17. In lecture I showed how to use this method to solve 1.2.1.

Question 4, 10 September 2003

In 2.1.2, how do I decide what the "basic operation" is?

Certainly it should be an operation on numbers (matrix entries) instead of one on vectors or matrices. You could either (a) decide which operation, addition or multiplication, is used more often and pick that, or (b, my preference) assume that either an addition or multiplication can be done in a single clock cycle, so that you add the number of additions to the number of multiplications.

Question 3, 10 September 2003

When it says "give an algorithm", do you want pseudocode or Java?

In general either is all right, as long as your answer indicates clearly what you want the computer to do to solve your problem. Java has the advantage that you can actually test your answer on a real computer, though we will rarely if ever require you to do this in this course. In 1.1.10, I've tried to give you more of an indication of what kind of code I want in Java terms, so that's a better one to answer in Java if you can.

Question 2, 6 September 2003

Is "no solution is possible" an acceptable answer for Problem 1.2.2?

It would be an acceptable answer if it were true, but it isn't (as you later realized yourself). In general, a problem could be "broken" like this for three reasons:

  1. It is a deliberate trick question,
  2. Levitin or I have made a mistake, or
  3. You are misunderstanding the problem in some way.

The most likely reason is (3). The way to find out which is to send Jeff and/or me an email question like "I don't think there's a solution to 1.2.2, and here is why." We can then identify which of the three cases you are in and either (1) reassure you that your reasoning is sound, (2) make a correction or clarification in the problem, or (3) identify where your understanding has gone wrong.

This is perhaps the aspect of mathematics that I find personally most attractive. Differences of opinion can usually be resolved by the truth-finding techniques of the field. If we have a valid proof to back up our opinion, then anyone who understands the relevant definitions properly should agree with us.

Question 1, 6 September 2003

In Problem 1.2.2, should I consider the possibility of stopping in the middle of the bridge, or returning to the side that you started from?

No. There is only one flashlight, and you may not abandon a person in the middle of the bridge without the flashlight. Once a group has started across, doing anything other than crossing at the group's fastest possible speed is pretty clearly a waste of time. So assume that the only possible moves ("atomic operations") are crossings by one or two people with the flashlight.

Last modified 8 September 2003