# 03 - CIS 121 Spring 2010 Data Structures and Introduction...

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

1 1/22/10 Lecture Notes 3 1 CIS 121 Spring 2010 Data Structures and Introduction to Algorithms using JAVA Lecture Notes 3: More analysis, Big-Theta, recurrence relations © © 2006 M.Goodrich & R.Tamassia (with permission) 1/22/10 Lecture Notes 3 2 Chapter 7 Reading Assignment

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

View Full Document
2 1/22/10 Lecture Notes 3 3 Exponentials and Logarithms [You should have review the basic rules that govern exponentials and logarithms, their relation with addition, subtraction, multiplication, and division.] Warm-up: a = log b iff 2 a = b (default base of log is 2 ) Moreover, both log x and 2 x are monotone functions: x y implies log x log y and 2 x 2 y THEOREM (we’ll assume this without proof) For any degree d 1 and any base b>1 1) n d is O(b n ) (very loose…) 2) b n is not O(n d ) 1/22/10 Lecture Notes 3 4 Exponentials and Logarithms, cont’d Corollary For any degree d 1 1) log n is O(n d ) 2) n d is not O(log n) Also, it’s easy to show that - if 1<a b then a n is O(b n ) - if 1<a<b then b n is not O(a n ). Indeed, suppose, toward a contradiction, that there are N,c>0 such that b n c a n for all n N. Taking the log , which is monotone, gives n log b log c + n log a hence n log c / (log b - log a) Contradiction! (why?)
3 1/22/10 Lecture Notes 3 5 Functions ordered by growth rate In the following list, if f(n), g(n) are two consecutive functions, then f(n) is O(g(n)) but g(n) is not O(f(n)). 1, log n, n, n log n, n 2 , n 100 , (1.5) n , 2 n , 3 n 1/22/10 Lecture Notes 3 6 More asymptotic notation, upper bound, lower bound w.c.r.t. = worst-case running time Saying that the w.c.r.t. is O(…) is often not satisfactory. For the orst code analysis we got w.c.r.t. is O(n 2 ) . Now, n is O(n 2 ) also, but we computed w.c.r.t. 3n 2 + 7n + 4. That gave us not only an (asymptotic) upper bound (Big-Oh) but also an (asymptotic) lower bound for the w.c.r.t. We can use the following definition to state such lower bounds: f(n) is Ω (g(n)) if there exist constants N and c > 0 such that f(i) c g(i) whenever i N. Big-Omega

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

View Full Document
1/22/10 Lecture Notes 3 7 Functions with the same growth rate So the w.c.r.t. of the orst code is O(n 2 ) and also is Ω (n 2 ) . If f(n) is O(g(n)) and f(n) is Ω (g(n)) then we say that f(n) and g(n) have the same asymptotic growth rate and we write f(n) is Θ (g(n)) (or equivalently g(n) is Θ (f(n)) ) If p(n) is a polynomial of degree d then p(n) is Θ (n d ). A Big-Theta bound is both an upper and a lower bound. We call it a tight bound. Big-Theta 1/22/10 Lecture Notes 3 8 Big-Oh and Big-Omega Notice that f(n) is Ω (g(n)) if and only if g(n) is O(f(n)) (prove it!) so from a pure math perspective we didn’t need Big-Omega. However, it is awkward to say
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 15

03 - CIS 121 Spring 2010 Data Structures and Introduction...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online