Exercise 4.3 has you compute the actual number of multiplications done by the third version of mod-expt given an exponent.
	  > (mod-expt-mults signing-exponent)
	  984
      
The dramatic speedup is due to the fact that at each step mod-expt divides the exponent in half.

Q: If e is the exponent, then how is the number of multiplications expressed in big-Theta notation?

Objective: Count how many times cards are handled when you sort n cards. (Call this H(n))

Count the number of card handlings:
Pass Number of stacks Size of each stack
1 n 1 = 20
2 n/2 2 = 21
3 n/4 4 = 22
4 n/8 8 = 23
... ... ...
p 1 n = ?
p 1 n = 2p-1
Since n cards are handled on each of log2n + 1 passes, the total number of handlings H(n) is:

Comparing n, nlogn, and n2

The chart below shows the functions n (red), nlogn (purple), and n2 (green) with the horizontal axis extending to n = 10.

Here are the values of the functions for n = 10:

n nlogn n2
10 23 100
For larger n the difference in the functions is more dramatic.

The chart to the right shows the functions n (red), nlogn (purple), and n2 (green) with the horizontal axis extending to n = 100, with n2 = 10,000.

Note the difference between the general shapes (that is, the "orders of growth") of this graph and the preceding one:

As n increases by an order of magnitude, the difference between nlogn and n2 becomes more dramatic.

n nlogn n2
10 23 100
100 461 10,000
1,000 6,908 1,000,000
10,000 92,103 100,000,000
100,000 1,151,293 10,000,000,000
1,000,000 13,815,511 1,000,000,000,000
If you could handle a card in a microsecond (one millionth of a second), merge sort on n = 1,000,000 would take about 14 seconds.

For selection sort: about 278 hours