Presentation is loading. Please wait.

Presentation is loading. Please wait.

Remarks on Fast Exp (4/2) How do we measure how fast any algorithm is? Definition. The complexity of an algorithm is a measure of the approximate number.

Similar presentations


Presentation on theme: "Remarks on Fast Exp (4/2) How do we measure how fast any algorithm is? Definition. The complexity of an algorithm is a measure of the approximate number."— Presentation transcript:

1 Remarks on Fast Exp (4/2) How do we measure how fast any algorithm is? Definition. The complexity of an algorithm is a measure of the approximate number of steps needed to finish as a function of the size of the input. For example, we showed a while back that the complexity of the Euclidean Algorithm is approximately 6.7 log 10 (b) where b is the smaller of the two numbers.

2 What about Fast Exp? What about Fast Exp? Since the exponent repeatedly doubles in Step 1 (and because we need to do Step 3 also), the complexity is approximately 2 log 2 (k) where k is the exponent. Example. If k = 12574, we need about 2(13) = 26 steps. Example. Suppose k has 100 decimal digits (i.e., log 10 (k)  100), then Fast Exp with require about 2(100 / log 10 (2))  664 steps.

3 About Binary Representations Why can any number be written as sum of powers of 2? It’s because mod 2, there are only two numbers, 0 and 1. In general, the base-b representation of a number k is given by k = C 0 b 0 + C 1 b 1 + C 2 b 2 +... + C n b n where n is the largest exponent such that b n  k (or, said another way log b (k) – 1 < n  log b (k)), and where all the coefficients C i lie in the range 0 to b – 1 (i.e., the coefficients are all the integers mod b). Example. The base-5 representation of 339 is 339 = 2(5 3 ) + 3(5 2 ) + 2(5 1 ) + 4(5 0 ) = 2324 5 What’s special about 2? All the coefficients C i are either 0 or 1. Hence any k is a sum of powers of 2!

4 Assignment for Friday “Absorb” Chapter 16 and the class notes from 3/31 and 4/2. Find the base-3 representation of 600. Use Fast Exp to compute 5 100 (mod 333) “by hand”. (Answer is 229).


Download ppt "Remarks on Fast Exp (4/2) How do we measure how fast any algorithm is? Definition. The complexity of an algorithm is a measure of the approximate number."

Similar presentations


Ads by Google