History of ClassS04CS141/Notes 03 31

ClassS04CS141 | recent changes | Preferences


Revision 6 . . May 4, 2004 7:02 pm by Neal
Revision 5 . . April 2, 2004 3:51 pm by Neal
  

Difference (from prior major revision) (no other diffs)

Changed: 23,60c23,25

Geometric sums




::1 + 2 + 4 + 8 + … + 2n = 2n+1 - 1.

More generally,

::1 + x + x2 + x3 + … + xn = (xn+1 - 1)/(x-1) unless x=1.

Using sum notation:
:: i=0n xi = (xn+1-1)/(x-1).

We showed a proof of this by multiplying both sides by (1-x) and simplifying.

For this class, the important thing is that for constant x > 1, the above is O(xn).

In words, with a geometrically increasing sum (where each term is a constant factor larger
than the previous term), the entire sum is proportional to the largest term.


(This is the key point of the class today!)

When x=2, the sum counts the number of interior nodes of a complete binary tree with
2n+1 leaves. Thus, the number of nodes in a complete binary tree is proportional to the
number of leaves.

This phenomenon is important for the design and analysis of algorithms.
For example, consider the next section.

Growable array




We discussed an implementation of a growable array, where, when the array needs
to be made larger, the space allocated for it is doubled. We discussed how the work
required for N operations is O(N+M), where M is the maximum index of any array cell
that is explicitly referenced.

To show this we used 1+2+4+… + 2n = O(2n).

The term 2i in the sum counts the work done in growing the array
from size 2i-1 to size 2i.
We discussed GeometricSums
and the GrowableArray
data structure.

ClassS04CS141 | recent changes | Preferences
Search: