40 likes | 163 Views
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.
E N D
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 log10(b) where b is the smaller of the two numbers.
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 log2(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., log10(k) 100), then Fast Exp with require about2(100 / log10(2)) 664 steps.
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 representationof a number k is given by k = C0 b0 + C1 b1+ C2 b2 + ... + Cnbnwhere n is the largest exponent such that bn k (or, said another way logb(k) – 1 < n logb(k)), and where all the coefficients Cilie in the range 0 to b – 1 (i.e., the coefficients are all the integers mod b). • Example. The base-5 representation of 339 is339 = 2(53) + 3(52) + 2(51) + 4(50) = 23245 • What’s special about 2? All the coefficients Ciare either 0 or 1.Hence any k is a sum of powers of 2!
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 5100 (mod 333) “by hand”. (Answer is 229).