1 / 4

Remarks on Fast Exp (4/2)

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.

melia
Download Presentation

Remarks on Fast Exp (4/2)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 log10(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 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.

  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 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!

  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 5100 (mod 333) “by hand”. (Answer is 229).

More Related