Notes+10.6

Another pass at estimating functions. 2^10 = 1024 ~ 10^3 Therefore, 1,000,000 = 10^6 ~ 2^20 10^9 ~ 2^30 7 billion takes 33 bits.

How did Gauss add the integers 1 + 2 + 3 + ... + 100 quickly and return to annoying his teacher? Answer: imagine writing it once left-to-right as above. Write it again as 100 + 99 + ... + 3 + 2 + 1 underneath the first series. Add vertically and see that the sum is 101 in each column. There are 100 columns, so the total is 100*101 = 10100. Except you wrote the series twice, so divide that answer by 2 = 5050. sum 1..N = N(N+1)/2 The trick of imagining writing it twice makes it easy to remember and works for ANY arithmetic series (one where the difference between successive terms is a constant). The biggest pit-fall? Fence-post error in counting the number of terms.

This is pretty close to how much work needs to be done to do insertion sort. We say it is Order(N^2). This means that as N gets large, the amount of work is "about" N^2 (times a constant and plus some little stuff that become relatively insignificant as N gets really large).

The BEST sort algorithms are Order(N lg N).

Why bother sorting things? Suppose you had a million items in an array, unsorted. If you only need to find one thing, once, it makes more sense just to rapidly look through the list. That takes linear time (Order(N)).