Note that we expect you to be familiar with mathematical induction. If you have not yet seen mathematical induction, you should review the handout discussing it and go to office hours if you have trouble.
The first thing we want to prove today is the equation:
Now that we have the basics down, we will use equations similar to the above frequently in our analysis of running times. Recall the formal definition of big-O:
This definition is required when doing a formal proof of running times. Before we get to that, the first step is to write down the recurrence equations for your program. Actually getting the recurrence equations is not a trivial task - the more complicated the program, the harder it is to figure out. At the basis of it is identifying the atomic operations of the program. This depends on the language you are using, etc. After identifying the atomic operations, you can combine them to determine the recursive calls and the constant values.
From experience and intuition, you know that insertion sort is
,
but now we want to prove it. Recall that the recurrence equations for
insertion sort are:
Both
and
are constants. From our discussion of big-O in
lecture, you know that an advantage of big-O is classifying programs
by obscuring the constants. Since we don't know what
or
are, we can assume that they are both one. If we did not assume that
they are one, we would simply have to scale the analysis accordingly
later on. Leaving them as one just makes the whole thing a bit
easier. That leaves us with the following recurrence equations for
insertion sort:
There are two ways to come about deciding that insertion sort is O(n2): iterative method, and the guess and prove method. (Note other methods do exist, though they do not work for all cases.) First we will try to show insertion sort is O(n2) by the iterative method:
Basically, we keep substituting away until we notice a pattern in the iterations. From this we note:
So the running time is explicitly known to be
with some constant
factors involved. This fits exactly into the high-level definition of
.
The other method is to guess what the big-O set is for the running
time and then prove it inductively using the formal definition. So,
out of the blue, we're going to say that the big-O running time of
insertion sort is
. Let's prove it!
First we choose constants
and
.
Property of
to prove
Proof by Induction on
Base Case:
Induction Step:
Induction Hypothesis:
Property to prove for
:
The above proves the right-hand side of the equation. The
left-hand side,
, is obviously true.
Now that we've proven the running times for insertion sort, let's do the same thing for merge sort. Recall that merge sort has the following recurrence relations:
Note again that we really don't need to pay attention to the constants in the equations. The 2 in front of the recursive call to the time equation is important however, so it must remain. That leaves us with the following recurrence equations to work with:
Counting the number of
values in the sum at the end, it is easy to
see that there are
of them. Thus the time is on the order of
and therefore
. So now we've done the analysis by using
the iterative method, let's try the guess and prove method.
First we choose constants
and
.
Property of
to prove
Proof by strong induction on
Base case:
Induction Step:
Induction Hypothesis:
It's important to note that big-O actually represents a set. So when
we write
, we're actually saying that the recurrence
equation is an element of the set of functions in
. This also
implies that
is a superset of
. [NOTE: when we ask for
big-O on exams and problem sets, we want the smallest big-O set the
function is contained in - otherwise we'll mark it wrong]. Given
this knowledge of sets, it is also the case that
.
And it is also the case that
. All this can be
proven using the formal definition of big-O shown earlier in section.
Asymptotic efficiency means having the smallest big-O possible. A
good example of this is Fast-Fourier Transform (FFT), which is a
method for multiplying two polynomials together. The ordinary method
for multiplying polynomials is
. FFT involves transforming the
polynomials into an intermediate format - this takes
.
Pointwise multiplication on this intermediate format is done, which
takes
time. Lastly, the resulting pointvalue intermediate format
is transformed back into a polynomial representation, which takes
time. Putting this altogether,
which is much better than
.
This document was generated using the LaTeX2HTML translator Version 99.2beta8 (1.43)
Copyright © 1993, 1994, 1995, 1996,
Nikos Drakos,
Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999,
Ross Moore,
Mathematics Department, Macquarie University, Sydney.
The command line arguments were:
latex2html -no_navigation -dir html -mkdir -noaddress -image_type gif -local_icons -show_section_numbers -split 0 -white -transparent induct.tex
The translation was initiated by Jeffrey M. Vinocur on 2001-02-22