analysis techniques pasi fränti 19.9.2013. ordo o(g) – upper bound f(n) ≤ c∙g(n) omega ...
Post on 02-Jan-2016
232 Views
Preview:
TRANSCRIPT
• Ordo O(g) – Upper Bound f(n) ≤ c∙g(n)• Omega (g) – Lower Bound f(n) ≥ c∙g(n)• Theta Θ(g) – Exact limit:
c1∙g(n) ≤ f(n) ≤ c2∙g(n)
Upper and lower bounds
3
• Upper limit
• For example: f(n) = 3n-7 = O(n)Suppose that c= 4 then
3n+7 ≤ 4n 7 ≤ n
which is true for all when n0=7
00 ),( :nc, if : )( nnngcnfgOf
Upper limit
Example of boundsT(N)=N-7
0
20
40
60
80
100
120
0 10 20 30 40 50 60 70 80 90 100
T (N )=N -7
g1(N )=N
g2(N )=N /8T(N)=(N)
N0=1
N0=8
T(N)=O(N)
Limit for polynomials
00
11
11)( nananananT m
mm
m
mmm
m
mmmm
mm
mm
mm
ncaaaaan
n
a
n
a
n
a
n
aan
nanananananT
)(
...
0121
01
12
21
00
11
22
11
Polynomial function:
Derivation of upper limit:
0121 selectingwhen aaaaac mm
mnOnT
Logarithm
)(log2 2 xyxy
)log(2
)log(1
2121
2121
2121
12
)log()log(
)log()log()log(
0)1log(
)log()log(
)log()log(
xx
a
xx
xax
xxxx
xxxx
xxxx
Definition:
Properties:
Summations
)(2
)1( 2
1
nnn
in
i
)(6
)12)(1( 3
1
2 nnnn
in
i
)(...21
1)1(
1
kkkn
i
k nn
k
ni
122 1
0
nn
i
i
1
11
0
a
aa
nn
i
i
Theorem: The depth s of a binary tree with N leafs is s ≥ log2N
Depth of a binary tree
s
N leaf nodes
• Initial case: For N=2, s = log2N=1
• Induction hypothesis: Trees of height s=k have at most N ≤ 2k leaves s ≥ log2N
• Induction step: – Trees of height s=k+1 consists of one or two
sub-trees of size k. Denote the number of leaf nodes as N1 and N2 .
– According to induction hypothesis, N1 ≤ 2k and N2 ≤ 2k.
– Number of leafs N = N1+N2 ≤ 2k+2k = 2k+1. Hence, the hypothesis holds for k+1.
Proof of the height
k
K+1
k k
1
There are N! possible permutations, of which one is the list in sorted order. Tree has N! leaf nodes.
It can be lower bounded
Height of the tree is therefore bounded by
2/2/12...)2()1(! NNNNNN
)log(2/log!log 2/ NNNN N
Proof of the lower bound
top related