Top Banner
Analysis techniques Pasi Fränti 19.9.2013
15

Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

Jan 02, 2016

Download

Documents

Jodie Norman
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

Analysis techniques

Pasi Fränti19.9.2013

Page 2: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

• 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

Page 3: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

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

Page 4: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

4

• Lower limit

• Exact bounds

Lower limit

00 ),( :nc, if : )( nnngcnfgf

gfgfgf )(

Page 5: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

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)

Page 6: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(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

Page 7: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

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:

Page 8: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

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

Page 9: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

Combinatory formulas

123...)2()1(! nnnn

Permutation:

)!(!

!

knk

n

k

n

Binomial factor:

Page 10: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

Lower bound for sorting

Page 11: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

a<b?

a<c? c<a?

c<b?b<c?

a b c

a c b c a b

c b a

b c a b a c

Sorting via comparisons

Page 12: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

Theorem: The depth s of a binary tree with N leafs is s ≥ log2N

Depth of a binary tree

s

N leaf nodes

Page 13: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

• 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

Page 14: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

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

Page 15: Analysis techniques Pasi Fränti 19.9.2013. Ordo O(g) – Upper Bound f(n) ≤ c∙g(n) Omega  (g)– Lower Bound f(n) ≥ c∙g(n) Theta Θ(g)– Exact limit: c 1 ∙g(n)

nennn

nenn nn

n

nn

12

12!

12

12

6.0

Stirling’s formula

nnnn 22 log!log

More strict lower bound