big o notation - github pagesΒ Β· 2021. 1. 2.Β Β· big o notation find the big o notation of n2+2n+1...
TRANSCRIPT
![Page 1: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/1.jpg)
Big O Notation
![Page 2: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/2.jpg)
Runtime of an algorithm
Running time of an algorithm depends on
i) Input size
6 13 14 25 33 43 51 53 64 72 84
6 13 14 25 33
Array size = 5
Array size = 11
![Page 3: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/3.jpg)
Runtime of an algorithm
Running time of an algorithm depends on
i) Input size
6 13 14 25 33 43 51 53 64 72 84
6 13 14 25 33
Array size = 5
Array size = 11
a function of the size of its inputf(n)n = input size
![Page 4: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/4.jpg)
Growth rate of a function
Rate of growth: How fast a function grows with the input size
0
200
400
600
800
1000
1200
1400
1600
1800
10 20 30 40
No
of
op
erat
ion
sn
f(n) = n
f(n) = n^2
f(n) = nf(n) = π2
![Page 5: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/5.jpg)
Asymptotic notation of a function
f(n) = 6π2 + 100n + 30
n >= 20
6π2 > 100n + 30
![Page 6: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/6.jpg)
Asymptotic notation of a function
f(n) = 6π2 + 100n + 30
The algorithm grows as π2
Drop coefficient 6 and terms 100n + 30. They are not significant enough.
![Page 7: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/7.jpg)
Asymptotic notation of a function
f(n) = 0.6π2 + 1000n + 3000
n >= 1000
0.6π2 > 1000n + 3000
![Page 8: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/8.jpg)
Asymptotic notation of a function
f(n) = 0.6π2 + 1000n + 3000
The algorithm grows as π2
![Page 9: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/9.jpg)
Asymptotic notation of a function
f(n) = 0.6π2 + 1000n + 3000
f(n) = 6π2 + 100n + 30
When we drop the constant coefficients and the less significant terms, we use asymptotic notation
These algorithm grows as π2
![Page 10: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/10.jpg)
Big O Notation
Given f(n): the actual growth rate of your algorithm as a function of input size find g(n) such that
C|g(n)| >= |f(n)| for n > k
Then f(n) = O (g(n))
![Page 11: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/11.jpg)
Big O Notation
Find the Big O Notation of n2 + 2n + 1
π π = π2 + 2π + 1 β€ π2 + 2π2 + π2
= 4π2 = Cg(n)
f(n) = O(g(n)) = O(π2),
Where k = 1, C = 4
Find k:n = 1, f(n) = 4, Cg(n) = 4n = 2, f(n) = 9, Cg(n) = 16For n > 1 Cg(n) >= f(n)
Hence, k = 1
![Page 12: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/12.jpg)
Big O Notation
Find the Big O Notation of n!
n! = 1.2.3 β¦ n <= n.n β¦ n
= ππ = C g(n)
f(n) = O(g(n)) = O(ππ),
Where k = 1, C = 1
Find k:n = 1, f(n) = 1, Cg(n) = 1n = 2, f(n) = 2, Cg(n) = 4For n > 1 Cg(n) >= f(n)
Hence, k = 1
![Page 13: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/13.jpg)
Big O Notation
Find the Big O Notation of log(n!)
![Page 14: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/14.jpg)
Big O Notation
If f1(x) = O(g1(x)) and f2(x) = O(g2(x))
(f1 + f2)(x) = O(max(g1(x), g2(x)))
(f1f2)(x) = O(g1(x)g2(x))
![Page 15: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/15.jpg)
Big O Notation
Find the Big O Notation of f(n) = 3nlog(n!) + (π2+ 3)log(n)
![Page 16: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/16.jpg)
Big O Notation
Find the Big O Notation of f(n) = 3nlog(n!) + (π2+ 3)log(n)
![Page 17: Big O Notation - GitHub PagesΒ Β· 2021. 1. 2.Β Β· Big O Notation Find the Big O Notation of n2+2n+1 ππ=π2+2π+1β€π2+2π2+π2 =4π2 = Cg(n) f(n) = O(g(n)) = O(π2),](https://reader036.vdocuments.us/reader036/viewer/2022062609/60fbc3121a373b2be67ed1d2/html5/thumbnails/17.jpg)
Common Big O Notation
Notation Name
O(1) Constant
O(logn) Logarithmic
O((logn)c) Poly-logarithmic
O(n) Linear
O(π2) Quadratic
O(ππ) Polynomial
O(ππ) Exponential