Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture aid 1 Devon M. Simmonds University of North Carolina, Wilmington CSC231 Data Structures.

Similar presentations


Presentation on theme: "Lecture aid 1 Devon M. Simmonds University of North Carolina, Wilmington CSC231 Data Structures."— Presentation transcript:

1 Lecture aid 1 Devon M. Simmonds University of North Carolina, Wilmington CSC231 Data Structures

2 Lecture aid Math Review: logarithmic functions

3 Lecture aid 3 properties of exponentials: a (b+c) = a b a c a bc = (a b ) c a b /a c = a (b-c) b = a log a b b c = a c*log a b properties of logarithms: log b (xy) = log b x + log b y log b (x/y) = log b x - log b y log b x a = alog b x log b a = log x a/log x b Math you need to Review

4 Lecture aid Logarithmic/Exponential Problems. Evaluate and/or simplify.  2 a =8  2 a =1024  2 a = n 2  log 8 32  2 log 4 9  log 12  2 log 9  2 4 2 3 == 2 12  2 4 2 3 == 2 7  3 15 /3 10

5 Lecture aid 5 Asymptotic Notation Big-Oh f(n) is O(g(n)) if f(n) is asymptotically less than or equal to g(n)

6 Lecture aid Big-Oh Growth Rate f(N) = O(g(N)) iff there are positive constants c and n 0 such that f(N)  c g(N) when N  n 0 – The growth rate of f(N) is less than or equal to the growth rate of g(N) – g(N) is an upper bound on f(N) – f(N) grows no faster than g(N) for “large” N

7 Lecture aid Big Oh: more examples N 2 / 2 – 3N = O(N 2 ) iff ∃ c, n 0 > 0 such that N 2 / 2 – 3N n 0 Proof N 2 / 2 – 3N <= N 2 – 3N (because N 2 / 2 is less than N 2 ) 0) = O(N 2 ) when c = 1 and n 0 = 1 NN2N2 N 2 /2-3N 11-2.5 24-4 39-4.5 1010020 5025001100 100100004700 2004000019400 500250000123500 10001000000497000

8 Lecture aid Big Oh: more examples N 2 + 3N = O(N 2 ) iff ∃ c, n 0 > 0 such that N 2 + 3N = n 0 Proof 3n = 3, so N 2 + 3n = 3 So N 2 + 3n < 2N 2 = O(N 2 ) where c = 2 and n 0 = 3 NN2N2 N 2 +3N 114 2410 3918 10100130 5025002650 1001000010300 2004000040600 500250000251500 100010000001003000

9 Lecture aid Big Oh: more examples 7N 2 + 10N + 3 = O(N 2 ) = O(N 3 ) Proof 10N + 3 1 and some c > 0 i.e, 10N + 3 10, c >= 1 So, 7N 2 + 10N + 3 10 = 8N 2 = O(N 2 ) ∀ n > 10, c >= 8 NN2N2 10N + 3 1113 2423 3933 10100103 11121113 12144123 15225153 30900303 502500503 100100001003 1000100000010003

10 Lecture aid Big Oh: more examples Prove the following 7N 2 + 10N + 3 = O(N 3 ) N 3 + 90N 2 + 14N = O(N 3 )

11 Lecture aid Big Oh: more examples log 10 N = O(log 2 N) = O(log N) Proof: log 10 N = log 2 N / log 2 10 = log 2 N / 3.32 = 1, c >= 1 = O(log 2 N) = O(log N) since log 2 N = log k N / log k 2 = O(log k N)

12 Lecture aid Big Oh: more examples log N + N = O(?)

13 Lecture aid Big Oh: more examples N 2 / 2 – 3N = O(N 2 ) 1 + 4N = O(N) 7N 2 + 10N + 3 = O(N 2 ) = O(N 3 ) log 10 N = log 2 N / log 2 10 = O(log 2 N) = O(log N) sin N = O(1); 10 = O(1), 10 10 = O(1) log N + N = O(?) log k N = O(N) for any constant k N = O(2 N ), but 2 N is not O(N) 2 10N is not O(2 N )

14 Lecture aid 14 Computing Prefix Averages Asymptotic analysis with two algorithms for prefix averages The i -th prefix average of an array X is average of the first (i  1) elements of X: A[i]  X[0]  X[1]  …  X[i])/(i+1) Computing the array A of prefix averages of another array X has applications to financial analysis

15 Lecture aid 15 A Prefix Averages Algorithm Algorithm prefixAverages1(X) Input array X of n integers Output array A of prefix averages of X A  new array of n integers for i  0 to n  1 do s  X[0] for j  1 to i do s  s  X[j] A[i]  s  (i  1) return A Algorithm prefixAverages2 runs in O(?) time

16 Lecture aid 16 Another Prefix Averages Algorithm Algorithm prefixAverages2(X) Input array X of n integers Output array A of prefix averages of X A  new array of n integers s  0 for i  0 to n  1 do s  s  X[i] A[i]  s  (i  1) return A Algorithm prefixAverages2 runs in O(?) time

17 Lecture aid 17 ______________________ Devon M. Simmonds Computer Science Department University of North Carolina Wilmington _____________________________________________________________ Qu es ti ons? Reading from course text:


Download ppt "Lecture aid 1 Devon M. Simmonds University of North Carolina, Wilmington CSC231 Data Structures."

Similar presentations


Ads by Google