110 likes | 366 Views
Big O notation. f = O( g ( n )). c g(n). There are c>0, n 0 so that for n>n 0 f ( n ) ≤ c g ( n ) c g ( n ): upper bound of f(n). f(n). n 0. [ Small o: for every c>0 there is n 0 so that: f ( n ) ≤ c g ( n ) ]. Big Ω notation. f = Ω ( g ( n )). f(n).
E N D
Big O notation f = O(g(n)) c g(n) There are c>0, n0 so that for n>n0 f(n) ≤ c g(n) c g(n): upper bound of f(n) f(n) n0 [ Small o: for every c>0 there is n0 so that: f(n) ≤ c g(n) ]
Big Ω notation f = Ω(g(n)) f(n) There are c>0, n0 so that for n>n0 c g(n) ≤ f(n) c g(n): lower bound of f(n) c g(n) n0 [ Small ω: for every c>0 there is n0 so that: c g(n) ≤ f(n) ]
Big Θ notation c2 g(n) There are c1,c2>0, n0 so that for n>n0 c1g(n) ≤ f(n) ≤ c2g(n) c1 g(n): lower bound of f(n) c2g(n): upper bound of f(n) f(n) c1 g(n)
~ notation • f(n)~g(n) f is equal to g asymptotically f(N) g(N)
Examples 1. T(n) = (n+1)2 find upper bound for T(n) 2. Is n3 O(0.001n3) ?
Example • Prove that n2 is not O(n)
Recursion • Very often a problem is decomposed to smaller ones • Solution to subproblem is simpler • Solutions are combined iteratively
Examples • T(N) = T(N-1) + N, N≥2, T(1)=1 • Loops to eliminate one item • T(N) = T(N/2)+1, N≥2, T(1)=1 • Halve the input • T(N) = T(N/2)+N, N≥2, T(1)=0 • Halve the input but examine every item in the input • T(N) = 2T(N/2)+N, N≥2, T(1)=0 • Halve the input and linear pass