



















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The concept of computational complexity, focusing on the growth rates of algorithms and the use of Big O notation for upper bounds in algorithm analysis. Topics include worst-case analysis, common shapes of growth functions, and the difference between linear, logarithmic, quadratic, and superlinear complexities.
Typology: Lecture notes
1 / 59
This page cannot be seen from the preview
Don't miss anything!
CS200 - Complexity 1
CS200 - Complexity 2
unit of space
8
Measuring the efficiency of algorithms
CS200 - Complexity 10
Efficiency of algorithms
q How are the algorithms coded? We want to compare the algorithms, not the implementations. q What computer should we use? Choice of operations could favor one implementation over another. q What data should we use? Choice of data could favor one algorithm over another CS200 - Complexity 11
Example: array copy
CS200 - Complexity 13
Example: linear Search
CS200 - Complexity 14 private int linSearch(int k){ for(int i = 0; i<A.length; i++ ){ if(A[i]==k) return i; } return -1; }
Growth rates A. Algorithm A requires n 2 / 2 steps to solve a problem of size n B. Algorithm B requires 5n+10 steps to solve a problem of size n n Which one would you choose? CS200 - Complexity 16
Growth rates n When we increase the size of input n , how the execution time grows for these algorithms? n We don’t care about small input sizes n 1 2 3 4 5 6 7 8 n 2 / 2 .5 2 4.5 8 12.5 18 24.5 32 5n+10 15 20 25 30 35 40 45 50 n 50 100 1,000 10,000 100, n 2 / 2 1250 5,000 500,000 50,000,000 5,000,000, 5n+10 260 510 5,010 50,010 500, CS200 - Complexity 17
Growth rates n Algorithm A requires n 2 / 2 +1 operations to solve a problem of size n n Algorithm B requires 5n + 10 operations to solve a problem of size n n For large enough problem size algorithm B is more efficient n Important to know how quickly an algorithm’s execution time grows as a function of program size q We focus on the growth rate: n Algorithm A requires time proportional to n^2 n Algorithm B requires time proportional to n n B’s time requirement grows more slowly than A’s time requirement (for large n) CS200 - Complexity 19
Order of magnitude analysis n Big O notation: A function f(x) is O(g(x)) if there exist two positive constants, c and k, such that f(x) ≤ c*g(x) ∀ x > k CS200 - Complexity 20