Proving correctness using a loop invariant is similar to mathematical induction. Some significant changes are that, when showing the maintenance part of the loop invariant, we may assume that the loop test passes, and there's an explicit termination condition to show, for which we may assume that the loop test fails.
maple
or mathematica
. Much of the
theory of differential equations can be applied to solving
recurrences. It is sometimes also useful to look for patterns by
computing the values explicitly, either top-down or bottom-up.Brief discussion of Quicksort and order statistics. We gave an analysis of Quicksort on a random input, showing that the expected number of comparisons is O(n log(n)). Next, we gave a few different variations, in which we used a randomized algorithm to find a good pivot. We tried taking k random pivots. First we showed that the probability that ALL k tries are bad is exponentially small in k. In this case, we could test each pivot and use one that works. We then showed that the probability that k/2 or more are bad is exponentially small in k. In this case, we could use the median pivot, since, if the median pivot is bad, then at least half of the tries are bad, and that's a low probability event.