lecture-8

# lecture-8 - CPSC 223 Algorithms Data Abstract Structures...

• 15

This preview shows pages 1–5. Sign up to view the full content.

9/23/10 1 CPSC 223 Algorithms & Data Abstract Structures Lecture 8: Algorithm Analysis and Sorting Today … Homework Homework 3 Due Homework 4 Assigned More on complexity analysis [Sect. 9.1] Binary search Bubble, selection, and insertion sort [Sect. 9.2] Next week: Midterm (Thurs.) CPSC 223 -­૒-­૒ Fall 2010 2

This preview has intentionally blurred sections. Sign up to view the full version.

9/23/10 2 Order-of-Magnitude Analysis Big O notation focuses algorithm growth rates an upper bound (running time will not be worse) independent of the particular implementation or computer used to execute the algorithm Given algorithm A , we say A requires time proportional to a function f ( n ) n is the size of the input we say that “ A is order f ( n )” … which we write as O ( f ( n )) CPSC 223, 2009 3 Order-of-Magnitude Analysis f ( n ) represents the algorithm’s growth rate as a function over input size n Examples: If A requires time directly proportional to n , then f ( n ) = n … which we write O ( n ) If A requires time proportional to n 2 , then f ( n ) = n 2 … which we write O ( n 2 ) CPSC 223, 2009 4
9/23/10 3 Order-of-Magnitude Analysis Notice that we don’t include constant terms e.g., instead of 6 n + 5 , we write O ( n ) … and instead of 6 n 2 + n – 8 , we write O ( n 2 ) We are interested in the algorithm’s general rate of growth This makes it easier to compare different solutions CPSC 223, 2009 5 Order-of-Magnitude Analysis We’re looking at input sizes large enough to make only the growth of the running time relevant We’re studying the “ asymptotic ” efficiency of algorithms We’re concerned with how the running time of an algorithm increases with the size of the input in the limit … as the size of the input increases without bound CPSC 223, 2009 6

This preview has intentionally blurred sections. Sign up to view the full version.

9/23/10 4 Order-of-Magnitude Analysis Definition of the Order of an Algorithm (textbook): Algorithm A is O ( f ( n )) if constants k and n 0 exist such that A requires no more than k · f ( n ) time units to solve a problem of size n n 0 Alternative definition of big O analysis [Cormen et al.] For a given function g ( n ) , we denote by O ( g ( n )) the set of functions O ( g ( n )) = { f ( n ) | there exist positive constants k and n 0 such that 0 f ( n ) k · g ( n ) for all n n 0 } Thus, big O gives an upper bound on a function f ( n ) to within a constant factor CPSC 223, 2009 7 Growth Rates
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern