ClassS04CS141 | ClassS04CS141 | recent changes | Preferences

Each problem was worth 20 points, and since there were five problems, the homework was worth 100 points. Subcases a) and b) in problems 1 and 2 were worth 10 points each. Problems 3a) and 3b) were worth 5 points each; problem 3c) was worth 10 points.

Overall, the solutions lacked precision and were somewhat chaotic. Here are the most common mistakes:

Problem 2a.

UNION takes O(n), FIND takes O(log n), so overall a sequence takes O(n logn)

First of all, a single UNION takes O(1) and if you call UNION n times, then the sequence of UNION's will take O(n). The whole sequence. If the sequence you construct consits of n UNION's there is no more room for FIND's.

Second, note that you were to construct a sequence that takes time at least n log n. This is not the same as constructing a sequence that takes O(n log n). Big-Oh means at most, and there is a great difference between "at least" and "at most".

Third, not every call to FIND takes time at least log n (or using the notation Ω(log n)). For example if you call FIND(e) and element e happens to be a root of some set (tree), then such a call takes only constant time. In the homework you should have explicitly said that you call FIND(e), where e is a leaf.

Problem 2b.

The whole point here was to show that FIND never takes time more than log n, in other words that each FIND takes time O(log n).

Problems 2a and 2b were often confused. Again, for 2a, you show that there are FIND's that take time at least log n; for 2b you show that there are no FIND's that take more than log n. Using the notation, in 2a you show that there are FIND's that take time Ω(log n) in 2b you show that all FIND's take time O(log n).

Problem 3.

If you want to solve a problem, you need to make sure you know and understand the right definitions. In particular, if you're asked to show that some function f(n) is O(g(n)), first you need to know what this means. Only after that you have a chance of actually giving a correct proof. Go back to the definition of the big-Oh notation and read it again. It mentions a constant c. Can c depend on n? Is the c from the definition the same as the c in problem 3c)?

i=1..n log i is dominated by the last term of the sum, which is log n, therefore the sum is O(log n), which is O(n log n)

This is wrong. This would be true if the terms in the sum formed a geometric sequence. They DO NOT in this example.

Problem 4.

If a vertex is added then one edge must be added

This is true, but the question is why? Why can't a vertex be added to a tree by connecting it with that tree with two or more edges? A complete proof should have that explanation.

In a tree each descendent is connected with its ancestor by an edge, and the root is not connected to anything so the number of edges must be one less than the number of vertices

Yes, but this is not a proof by induction. Here you map vertices to edges one to one, except the root. This is a completely different strategy...

ClassS04CS141 | ClassS04CS141 | recent changes | Preferences
This page is read-only | View other revisions
Last edited May 2, 2004 4:53 pm by (diff)