{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full Document Right Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full Document Right Arrow Icon
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
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}