• Keine Ergebnisse gefunden

denotes the set of functions f: IN  IN, for that two positive constants c ∈ IR≥0

N/A
N/A
Protected

Academic year: 2022

Aktie "denotes the set of functions f: IN  IN, for that two positive constants c ∈ IR≥0"

Copied!
9
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Orders of magnitude („Big-O Notation“)

)}

( )

( : ,

, 0 :

: { : ) (

. :

0 0

0 0

n g c n

f n n that such

IN n

c IR

IN f

g O

IR IN

g Let

denotes the set of functions f: IN  IN, for that two positive constants c ∈ IR≥0 and n0

∈IN exist, such that for all n ≥ n0 it is: f(n) ≤ c*g(n)

Remark: This asymptotic notation disregards constants and terms of lower (One says: if f∈O(g) then, asymptotically, f grows at most as fast as g.)

Claim: For a polynomial f(n) = amnm + ... + a0 of degree m with positive coefficient am it is valid: f ∈O(nm) [Remark: more precisely O(n → nm)]

Proof: f(n) ≤ |am| nm + ... + |a1| n + |a0|

≤ (|am| + |am-1| / n +... + |a0| / nm) ⋅ nm

≤ (|am| + |am-1| +... + |a0|) ⋅ nm

Now, c = |am| + |am-1| +... + |a0| and n0=1 implies the claim.

(2)

Further definitions: Again, let f, g: I IR≥0

- f ∈ (g) g ∈ (f)

(„asymptotically, f grows at least as fast as g“)

- f ∈ (g) f ∈ (g)

und

g ∈ (f)

(„asymptotically, f and g grow equally fast“)

-

(„f grows less fast than g“)

- F ∈ (g) g ∈o(f)

(„f grows faster than g“)

Instead of f ∈O(g), people sometimes write f = O(g). The same with o, , , .

Orders of magnitude, further notations

o(g ) : { f : IN IN : c 0 n

0

IN, so dass n n

0

: f (n) c g(n)}

(3)

Orders of magnitude, examples

• Let f(n) be the number of comparisons of a sequential search for the maximum of a number-sequence with n elements. Then f(n) ∈O(n), because running over the input once finfs the maximum number.

Then again, every algorithm has at least to inspect each element of the input in order to find the maximum. Therefore, every algorithm for this problem has a running time of f(n) ∈ (n).

• Matrix Multiplication: Let A and B be quadratic n x n matrices. The entries cij

of C = A⋅B result from cij = ∑nk=1 aik ⋅bkj. Seemingly, n multiplications and n additions per entry. As n2 many entires of C have to be computed , the outcome of the total effort of the „ovbious“ algorithm is: n2(n+n-1) = 2n3 – n2 ∈ O(n3). Moreover, each algorithm for this purpose will consume (n2) operations.

The fastest, currently known algorithm consumes O(n2.376) operations.

(4)

Orders of magnitude, examples

• n∈ o(n2), n2 ∈ O(n2), n2 ∈ o(n2)

• for i = 1 to n do for i = 1 to n do

for j = 1 to n do for j = i+1 to n do

perform an operation perform f(n) operations

end do end do

end do end do

O(n2) operations O(n2⋅f(n)) operations

(5)

11.04.2012 | Komplexität | 6

Orders of magnitude, remarks

a) The relation o(...) is transitive

f(n) = o(g(n) and g(n)=o(h(n)) ⇒ f(n) = o(h(n))

b) The relation o(...) can be used for classifiying various functions. E.g. it is valid for 0 < ε < 1 < c:

1 = o(log log n) constant functions

log log n = o(log n) double logarithmic funktions log n = o(nε) logarithmic funktions

nε = o(nc) roots

nc = o(nlog n) polynomials

nlog n = o(cn) subexponential functions cn = o(nn) exponential functions

nn = o(ccn) super exponential functions

(6)

Orders of magnitude, examples

log n n n log n n2 n3 2n

0 1 0 1 1 2

1 2 2 4 8 4

2 4 8 16 64 16

3 8 24 64 512 256

4 16 64 256 4096 65536

5 32 160 1024 32768 4294967296

The following table shows the growth of various functions :

(7)

16.04.2012 | Komplexität| 8

Orders of magnitude, computing rules

• For a constant c, it is c∈O(1)

• c⋅f(n)∈O(f(n)), clear with definition of O-notation

• O(f)+O(f)⊆O(f). Let g and h be functions from O(f). Then, there are cg, ch, ng and nh such that ... (exercise  )

• O(O(f))=O(f) with def.

• O(f)⋅O(g)⊆O(f⋅g) (exercise)

• O(f+g)=O(max{f(n),g(n)}).

Let h ∈ O(f+g). Then, there are positive constants c and n0, such that for all n≥n0 it is: h(n) ≤ c⋅(f+g)(n) ≤ c⋅2⋅max{f,g}(n). Thus, h(n) ∈ O(max{f,g}).

The other direction, h ∈ O(max{f,g}). Thus, there are positive constants c and n0, such that for all n≥n0 it is valid: h(n) ≤c⋅max{f,g}(n) ≤ c⋅(f+g)(n),

and thus h ∈ O(f+g).

(8)

Orders of magnitude, the O-notationen („Master Theorem“)

.) /

for or /

for stands

either /

where (

) ( )

/ ( )

( Let

. :

) ( let and

constants 1

, 1

Let

0 0

b n b

n b

n

n f b

n aT n

T

IR IN

n T b

a

)) ( ( )

(

then ,

large ly

sufficient for

) ( )

/ ( such that

1 0

with c

a is there if

and ), (

) ( with 0

if

) log (

) (

then ),

( )

( if

) (

) (

then ),

( )

( with 0

if

log log

log log

log

n f n

T

n n

f c b

n f a

c n

n f

n n

n T

n n

f

n n

T

n O n

f

a a

a a

a

b b

b b

b

Note:

There are other than

these 3 cases!

(9)

Orders of magnitude, the O-notationen („Master Theorem“)

Examples:

then is: a=9, b=3, f(n)=n, and thus nlogba = nlog39=n2 Therefore, f(n)=O(nlog39-ε), and we close with case 1:

T(n) = Θ(n2)

then is: a=1, b=3/2, f(n)=1 and nlogba = nlog3/21=n0=1

Case 2, becausef(n) = Θ(nlogba)=Θ(1) also: T(n) = Θ(log n)

n n

T n

T( ) 9 ( /3 )

1 ) 3 / 2 ( )

(n T n

T

Referenzen

ÄHNLICHE DOKUMENTE

We mention theoretical work on prediction properties of Pad´e approximants and related algorithms like the epsilon algorithm, and the iterated Aitken and Theta algorithms

Mitchell and Wynters [8] show that already computing the pair of tours that together see a simple rectilinear polygon is NP-hard, if we want to minimize the length of the longest of

As solving this problem exactly is time-consuming, a greedy evaluation procedure is used for approximating the quality of intermediate leader solution candidates, which is described

Keywords Acceptance-rejection algorithm · Bimodality · Circular distribution · Markov chain Monte Carlo · Methods of Ferrari and Weierstrass · Piecewise linear envelope

The objective of this study was to measure the rheological characteristics of different set yoghurts with a vane directly in the yoghurt cup “as it is” without partial destruction

Instead of projecting one point at a time onto the nondominated frontier - like in the original reference point approach by Wierzbicki [1980] - Korhonen and Laakso [1986] proposed

Wir haben einen Fehlschuss getan wie der Vikari, der beim Mittagessen meinte, die Leute seien wegen seiner Predigt so zahlreich in die Kirche gekommen.. Worauf

From Ramanujan’s Lost Note Book (Andrews 1979), Mock Theta Functions (2) (Watson 1937), G... i.e., the rank of a partition and that of the conjugate partition differ only