0% found this document useful (0 votes)
10 views1 page

Math Cheatsheet Algorithm Analysis

poiu

Uploaded by

Vlad 29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Math Cheatsheet Algorithm Analysis

poiu

Uploaded by

Vlad 29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Algorithm Analysis - Math CheatSheet

Logarithm properties Asymptotic Complexities


• Sometimes we may obtain a simpler expression by
• Definition: base logbase x
=x Assuming: limn→∞ ( fg(n)
(n)
)=L changing variables:
logb (x)

• Base change: loga (x) = Example: T (n) = 2 ∗ T ( n) + log(n)
logb (a) • 0 ≤ L < ∞ ⇒ f (n) ∈ O(g(n))

• Product rule: logb (x ∗ y) = logb (x) + logb (y) • 0 < L < ∞ ⇒ f (n) ∈ Θ(g(n)) 1. Let n = 2m → m = log(n) → n = 2m/2
2. Let S(m) = T (2m )
• Quotient rule: logb (x/y) = logb (x) − logb (y) • 0 < L ≤ ∞ ⇒ f (n) ∈ Ω(g(n))
• alogB (b) = blogB (a) Then: T (2m ) = 2 ∗ T (2m/2 ) + m
• L = 0 ⇒ f (n) ∈ o(g(n))
→ S(m) = 2 ∗ S(m/2) + m
Common derivatives • L = ∞ ⇒ f (n) ∈ ω(g(n)) → S(m) = θ(m ∗ log(m)) – Master Th.
→ T (n) = T (2m ) = S(m) = θ(m ∗ log(m))
F(x) F(x)’
Master Theorem → T (n) = θ(log(n) ∗ log(log(n)))
xn n ∗ x(n−1) s
bx bx ∗ ln(b) Suppose: T (n) = a ∗ T (n/b) + f (n), T (1) = θ(1). • It may be useful to search for a lower and an upper
1 Subject to: a ≥ 1, b > 1, f is an asymptotically positive
logb (x) x∗ln(b) bound that is easier to compute.
f (x) ∗ g(y) f (x)0 ∗ g(y) + f (x) ∗ g(y)0 function. Plogb (n)−1 i Example: T (n) = T (n/2 − log2 (n)) + 1
f (x) f (x)0 ∗g(y)−f (x)∗g(y)0 Then: T (n) = i=0 a ∗ f (n/bi ) + θ(nlogb (a) )
g(y) g(x)2 Proof using recursion trees: Consider:
0 0
f (g(x)) f (g(x)) ∗ g (x) T1 (n) = T1 (n/4) + 1 → T1 (n) = θ(log(n))
• logb (n) - height of the recursion tree
T2 (n) = T2 (n/2) + 1 → T2 (n) = θ(log(n))
L’Hospital’s Rule
• a ∗ f (n/b ) - cost of all internal nodes at depth i
i i
Since: n/4 ≤ n/2 − log2 (n) ≤ n/2
Assuming: → T1 (n) ≤ T (n) ≤ T2 (n)
• θ(nlogb (a) ) - cost associated with the leaves
• limx→a f (x) and limx→a g(x) are either 0 or ∞ → T (n) ∈ θ(log(n))
0
Master Theorem
• limx→a fg0 (x)
(x)
exists
1. f (n) = O(nlogb (a)− ), for some constant  > 0
0
Then: limx→a fg(x)
(x)
= limx→a fg0 (x)
(x) then T (n) = θ(nlogb (a) )
2. f (n) = θ(nlogb (a) ), then T (n) = θ(nlogb (a) log(n))
Useful sums
Pn n∗(n+1) 3. f (n) = Ω(nlogb (a)+ ), for some constant  > 0 and
• i=0 i = 2 if a ∗ f (n/b) ≤ c ∗ f (n), for some constant c < 1
Pn n∗(n+1)(2n+1) and all sufficiently large n, then T (n) = θ(f (n))
• i=0 i2 = 6


Pn
ip ∈ θ(np+1 ) Extension of Master Theorem
i=0
Pn Assuming: f (n) = O(nlogb (a) ∗ logb (n)α ). Then:
• i=0 2i = 2(n+1) − 1
1. α < −1 → T (n) = θ(nlogb (a) )
Pn a∗(1−r n )
• i=1 a ∗ ri−1 = 1−r
2. α = −1 → T (n) = θ(nlogb (a) logb (logb (n)))
Pn x−(n+1)∗xn+1 +n∗xn+2
• i=0 i ∗ xi = (x−1)2 3. α > −1 → T (n) = θ(nlogb (a) logb (n)α+1 )
(source)
Pn
• 1
i=1 x ∈ θ(log(n))
Pn
• i=1 ln(j) = ln(n!) = n ∗ ln(n) − n + O(ln(n))

You might also like