This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Lecture 3: What makes an algorithm more acceptable? Daniel Frances c 2012 Contents 1 An alternate method for computing F n 2 2 Higher order polynomial algorithms 2 3 Importance of highest order term 2 4 BigO Notation 5 5 BigO Analysis 5 5.1 Addition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 5.2 Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 5.3 Multiplication Revisited using a Divider and Conquer approach . . . . . . 7 5.4 Exponentiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.5 LP with Simplex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.6 LP Revisited  Development of Interior Point Methods . . . . . . . . . . . . 11 5.7 Integer Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 5.8 Integer Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1 1 An alternate method for computing F n Although the O n values were computed almost identically to the Fibonacci numbers we did not have to wait at all to be able to compute O 200 . So obviously we did not use fib1 for our computations. What did we do in Excel? As we computed the F ,F 1 ,F 2 ... values for n starting with 0 and 1, we stored the results! Then to calculate the next value of F n we did not recursively recalculate F n 1 ,F n 2 ,...,F 2 ,F 1 ,F . Instead we simply retrieved the stored values. Formally we used a new algorithm fib2(n). Algorithm 1.1. function fib2(n) if n=0 return 0 if n=1 return 0 create an array f[0 ...n] f(0)=f(1)=0 for i=2 ...n f(i)=f(i1)+f(i2) return f(n) Like before lets analyze the number of operations required to calculate F n using fib2(n). This time O n = n 1 and no exponential behaviour. 2 Higher order polynomial algorithms What if we had found an algorithm fib3 fo which O n = 3 n 5 + 2 n 4 + 5 n 3 + n 2 1 For example in that case to calculate F 200 it would have taken 3.2E11 operations. Even assuming a 1 GigaFlops PC=1E10 Flops the computation would take 32 seconds. Most importantly the polynomial function never explodes as we saw in the exponential graph. 3 Importance of highest order term What happens if we ignore the lower order terms in O n ? Figure 3 plots both the full polynomial and only the higher order terms. While there is a small difference for small n, this difference quickly disappears for larger n. As a result we would normally say that the number of operations is of the order of 3 n 5 . 2 Figure 1: Fib2 analysis n Basics # (by hand) O n return 0 1 return 0 2 f(2) 1 1 3 f(3) 2 2 4 f(4) 3 3 5 f(5) 4 4 6 f(6) 5 5 7 6 8 7 9 8 10 9 11 10 12 11 13 12 14 13 15 14 16 15 17 16 18 17 19 18 20 19 21 20 22 21 23 22 24 23 25 24 26 25 27 26 28 27 Figure 2: Polynomial analysis 0 50 100 150 200 250 On 3 Figure 3: Full Polynomial vs 3 n 55.E+04 0.E+00 5.E+04 1.E+05 2.E+05 2.E+05 3.E+05 3.E+05 4.E+05 0 2 4 6 8 10 12 Full Polynomial On=3n5 2.E+11 0.E+00 2.E+11 4.E+11 6.E+11 8.E+11 1.E+12 1.E+12 0 50 100 150 200 250 Full Polynom On=3n5 4 Table 1: Complexity Measure Notation...
View
Full
Document
 Spring '12
 Frances

Click to edit the document details