Module 6 Orders of Growth Module 6 Orders

  • Slides: 23
Download presentation
Module #6 – Orders of Growth Module #6: Orders of Growth Rosen 5 th

Module #6 – Orders of Growth Module #6: Orders of Growth Rosen 5 th ed. , § 2. 2 ~22 slides, ~1 lecture 2020 -10 -28 (c)2001 -2003, Michael P. Frank 1

Module #6 – Orders of Growth (§ 1. 8) • For functions over numbers,

Module #6 – Orders of Growth (§ 1. 8) • For functions over numbers, we often need to know a rough measure of how fast a function grows. • If f(x) is faster growing than g(x), then f(x) always eventually becomes larger than g(x) in the limit (for large enough values of x). • Useful in engineering for showing that one design scales better or worse than another. 2020 -10 -28 (c)2001 -2003, Michael P. Frank 2

Module #6 – Orders of Growth - Motivation • Suppose you are designing a

Module #6 – Orders of Growth - Motivation • Suppose you are designing a web site to process user data (e. g. , financial records). • Suppose database program A takes f. A(n)=30 n+8 microseconds to process any n records, while program B takes f. B(n)=n 2+1 microseconds to process the n records. • Which program do you choose, knowing you’ll want to support millions of users? 2020 -10 -28 (c)2001 -2003, Michael P. Frank 3

Module #6 – Orders of Growth • On a graph, as you go to

Module #6 – Orders of Growth • On a graph, as you go to the right, a faster growing function eventually becomes larger. . . 2020 -10 -28 Value of function Visualizing Orders of Growth f. A(n)=30 n+8 f. B(n)=n 2+1 Increasing n (c)2001 -2003, Michael P. Frank 4

Module #6 – Orders of Growth Concept of order of growth • We say

Module #6 – Orders of Growth Concept of order of growth • We say f. A(n)=30 n+8 is order n, or O(n). It is, at most, roughly proportional to n. • f. B(n)=n 2+1 is order n 2, or O(n 2). It is roughly proportional to n 2. • Any O(n 2) function is faster-growing than any O(n) function. • For large numbers of user records, the O(n 2) function will always take more time. 2020 -10 -28 (c)2001 -2003, Michael P. Frank 5

Module #6 – Orders of Growth Definition: O(g), at most order g Let g

Module #6 – Orders of Growth Definition: O(g), at most order g Let g be any function R R. • Define “at most order g”, written O(g), to be: {f: R R | c, k: x>k: f(x) cg(x)}. – “Beyond some point k, function f is at most a constant c times g (i. e. , proportional to g). ” • “f is at most order g”, or “f is O(g)”, or “f=O(g)” all just mean that f O(g). • Sometimes the phrase “at most” is omitted. 2020 -10 -28 (c)2001 -2003, Michael P. Frank 6

Module #6 – Orders of Growth Points about the definition • Note that f

Module #6 – Orders of Growth Points about the definition • Note that f is O(g) so long as any values of c and k exist that satisfy the definition. • But: The particular c, k, values that make the statement true are not unique: Any larger value of c and/or k will also work. • You are not required to find the smallest c and k values that work. (Indeed, in some cases, there may be no smallest values!) 2020 -10 -28 However, you should prove that the values you choose do work. 7 (c)2001 -2003, Michael P. Frank

Module #6 – Orders of Growth “Big-O” Proof Examples • Show that 30 n+8

Module #6 – Orders of Growth “Big-O” Proof Examples • Show that 30 n+8 is O(n). – Show c, k: n>k: 30 n+8 cn. • Let c=31, k=8. Assume n>k=8. Then cn = 31 n = 30 n + n > 30 n+8, so 30 n+8 < cn. • Show that n 2+1 is O(n 2). – Show c, k: n>k: n 2+1 cn 2. • Let c=2, k=1. Assume n>1. Then cn 2 = 2 n 2 = n 2+n 2 > n 2+1, or n 2+1< cn 2. 2020 -10 -28 (c)2001 -2003, Michael P. Frank 8

Module #6 – Orders of Growth • Note 30 n+8 isn’t less than n

Module #6 – Orders of Growth • Note 30 n+8 isn’t less than n anywhere (n>0). • It isn’t even less than 31 n everywhere. • But it is less than 31 n everywhere to the right of n=8. 2020 -10 -28 Value of function Big-O example, graphically cn = 31 n 30 n+8 O(n) n>k=8 Increasing n (c)2001 -2003, Michael P. Frank 9

Module #6 – Orders of Growth Useful Facts about Big O • Big O,

Module #6 – Orders of Growth Useful Facts about Big O • Big O, as a relation, is transitive: f O(g) g O(h) f O(h) • O with constant multiples, roots, and logs. . . f (in (1)) & constants a, b R, with b 0, af, f 1 -b, and (logb f)a are all O(f). • Sums of functions: If g O(f) and h O(f), then g+h O(f). 2020 -10 -28 (c)2001 -2003, Michael P. Frank 10

Module #6 – Orders of Growth More Big-O facts • c>0, O(cf)=O(f+c)=O(f) • f

Module #6 – Orders of Growth More Big-O facts • c>0, O(cf)=O(f+c)=O(f) • f 1 O(g 1) f 2 O(g 2) – f 1 f 2 O(g 1 g 2) – f 1+f 2 O(g 1+g 2) = O(max(g 1, g 2)) = O(g 1) if g 2 O(g 1) 2020 -10 -28 (c)2001 -2003, Michael P. Frank (Very useful!) 11

Module #6 – Orders of Growth (§ 1. 8) - So Far • For

Module #6 – Orders of Growth (§ 1. 8) - So Far • For any g: R R, “at most order g”, O(g) {f: R R | c, k x>k |f(x)| |cg(x)|}. – Often, one deals only with positive functions and can ignore absolute value symbols. • “f O(g)” often written “f is O(g)” or “f=O(g)”. – The latter form is an instance of a more general convention. . . 2020 -10 -28 (c)2001 -2003, Michael P. Frank 12

Module #6 – Orders of Growth Order-of-Growth Expressions • “O(f)” when used as a

Module #6 – Orders of Growth Order-of-Growth Expressions • “O(f)” when used as a term in an arithmetic expression means: “some function f such that f O(f)”. • E. g. : “x 2+O(x)” means “x 2 plus some function that is O(x)”. • Formally, you can think of any such expression as denoting a set of functions: “x 2+O(x)” : {g | f O(x): g(x)= x 2+f(x)} 2020 -10 -28 (c)2001 -2003, Michael P. Frank 13

Module #6 – Orders of Growth Order of Growth Equations • Suppose E 1

Module #6 – Orders of Growth Order of Growth Equations • Suppose E 1 and E 2 are order-of-growth expressions corresponding to the sets of functions S and T, respectively. • Then the “equation” E 1=E 2 really means f S, g T : f=g or simply S T. • Example: x 2 + O(x) = O(x 2) means f O(x): g O(x 2): x 2+f(x)=g(x) 2020 -10 -28 (c)2001 -2003, Michael P. Frank 14

Module #6 – Orders of Growth Useful Facts about Big O • f, g

Module #6 – Orders of Growth Useful Facts about Big O • f, g & constants a, b R, with b 0, – af = O(f); – f+O(f) = O(f); (e. g. 3 x 2 = O(x 2)) (e. g. x 2+x = O(x 2)) • Also, if f= (1) (at least order 1), then: 2020 -10 -28 – |f|1 -b = O(f); (e. g. x 1 = O(x)) – (logb |f|)a = O(f). (e. g. log x = O(x)) – g=O(fg) (e. g. x = O(x log x)) – fg O(g) (e. g. x log x O(x)) – a=O(f) (e. g. 3 = O(x)) (c)2001 -2003, Michael P. Frank 15

Module #6 – Orders of Growth Definition: (g), exactly order g • If f

Module #6 – Orders of Growth Definition: (g), exactly order g • If f O(g) and g O(f) then we say “g and f are of the same order” or “f is (exactly) order g” and write f (g). • Another equivalent definition: (g) {f: R R | c 1 c 2 k x>k: |c 1 g(x)| |f(x)| |c 2 g(x)| } • “Everywhere beyond some point k, f(x) lies in between two multiples of g(x). ” 2020 -10 -28 (c)2001 -2003, Michael P. Frank 16

Module #6 – Orders of Growth Rules for • Mostly like rules for O(

Module #6 – Orders of Growth Rules for • Mostly like rules for O( ), except: • f, g>0 & constants a, b R, with b>0, af (f), but Same as with O. f (fg) unless g= (1) Unlike O. |f| 1 -b (f), and Unlike with O. (logb |f|)c (f). Unlike with O. • The functions in the latter two cases we say are strictly of lower order than (f). 2020 -10 -28 (c)2001 -2003, Michael P. Frank 17

Module #6 – Orders of Growth example • Determine whether: • Quick solution: 2020

Module #6 – Orders of Growth example • Determine whether: • Quick solution: 2020 -10 -28 (c)2001 -2003, Michael P. Frank 18

Module #6 – Orders of Growth Other Order-of-Growth Relations • (g) = {f |

Module #6 – Orders of Growth Other Order-of-Growth Relations • (g) = {f | g O(f)} “The functions that are at least order g. ” • o(g) = {f | c>0 k x>k : |f(x)| < |cg(x)|} “The functions that are strictly lower order than g. ” o(g) O(g) (g). • (g) = {f | c>0 k x>k : |cg(x)| < |f(x)|} “The functions that are strictly higher order than g. ” (g). 2020 -10 -28 (c)2001 -2003, Michael P. Frank 19

Module #6 – Orders of Growth Relations Between the Relations • Subset relations between

Module #6 – Orders of Growth Relations Between the Relations • Subset relations between order-of-growth sets. R R ( f ) O( f ) • f o( f ) 2020 -10 -28 ( f ) (c)2001 -2003, Michael P. Frank 20

Module #6 – Orders of Growth Why o(f) O(x) • A function that is

Module #6 – Orders of Growth Why o(f) O(x) • A function that is O(x), but neither o(x) nor (x): 2020 -10 -28 (c)2001 -2003, Michael P. Frank 21

Module #6 – Orders of Growth Strict Ordering of Functions • Temporarily let’s write

Module #6 – Orders of Growth Strict Ordering of Functions • Temporarily let’s write f g to mean f o(g), f~g to mean f (g) • Note that • Let k>1. Then the following are true: 1 log n ~ logk n n 1/k n n log n nk kn n! nn … 2020 -10 -28 (c)2001 -2003, Michael P. Frank 22

Module #6 – Orders of Growth Review: Orders of Growth (§ 1. 8) Definitions

Module #6 – Orders of Growth Review: Orders of Growth (§ 1. 8) Definitions of order-of-growth sets, g: R R • O(g) {f | c>0 k x>k |f(x)| < |cg(x)|} • o(g) {f | c>0 k x>k |f(x)| < |cg(x)|} • (g) {f | g O(f)} • (g) {f | g o(f)} • (g) O(g) 2020 -10 -28 (c)2001 -2003, Michael P. Frank 23