1.1. 

Question: Suppose we have an algorithm with worst case complexity O(n).

True or false: It is possible for that algorithm to have average case complexity O(n2).

False. If it were true, the average case time would be increasing faster than the worst case time. Eventually, that means that the average case time for some large n would be larger than the worst case among all input sets of size n. But an average can never be larger than the maximum value in the set being averaged.

So the only way this statement could be true is in the trivial sense that any O(n) is also O(n2). That trivial case is ruled out by the no better than stipulation.

This is an important idea to keep in mind as we discuss the rules for average case analysis. The worst-case analysis rules all apply, because they do provide an upper bound. But that bound is sometimes not as tight as it could be. One of the things that makes average case analysis tricky is recognizing when we can get by with the worst-case rules and when we can gain by using a more elaborate average-case rule. There's no hard-and fast way to tell --- it requires the same kind of personal judgment that goes on in most mathematical proofs.


In the Forum:

(no threads at this time)