SlideShare uma empresa Scribd logo
1 de 39
Asymptotic Notation,
Asymptotic Notation,
Review of Functions &
Review of Functions &
Summations
Summations

December 20, 2013

Comp 122, Spring 2004
Asymptotic Complexity
 Running time of an algorithm as a function of
input size n for large n.
 Expressed using only the highest-order term in
the expression for the exact running time.
 Instead of exact running time, say Θ(n2).
 Describes behavior of function in the limit.

 Written using Asymptotic Notation.

ymp - 2

Comp 122
ymp - 3

Asymptotic Notation
 Θ, O, Ω, o, ω
 Defined for functions over the natural numbers.
 Ex: f(n) = Θ(n2).
 Describes how f(n) grows in comparison to n2.
 Define a set of functions; in practice used to compare
two function sizes.
 The notations describe different rate-of-growth
relations between the defining function and the
defined set of functions.

Comp 122
Θ-notation
For function g(n), we define Θ(g(n)),
big-Theta of n, as the set:
Θ(g(n)) = {f(n) :
∃ positive constants c1, c2, and n0,
such that ∀n ≥ n0,
we have 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n)

}
Intuitively: Set of all functions that
have the same rate of growth as g(n).

g(n) is an asymptotically tight bound for f(n).

ymp - 4

Comp 122
Θ-notation
For function g(n), we define Θ(g(n)),
big-Theta of n, as the set:
Θ(g(n)) = {f(n) :
∃ positive constants c1, c2, and n0,
such that ∀n ≥ n0,
we have 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n)

}
Technically, f(n) ∈ Θ(g(n)).
Older usage, f(n) = Θ(g(n)).
I’ll accept either…

f(n) and g(n) are nonnegative, for large n.
ymp - 5
Comp 122
ymp - 6

Example
Θ(g(n)) = {f(n) : ∃ positive constants c1, c2, and n0,
such that ∀n ≥ n0, 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n)}

 10n2 - 3n = Θ(n2)
 What constants for n0, c1, and c2 will work?
 Make c1 a little smaller than the leading
coefficient, and c2 a little bigger.
 To compare orders of growth, look at the
leading term.
 Exercise: Prove that n2/2-3n= Θ(n2)
Comp 122
ymp - 7

Example
Θ(g(n)) = {f(n) : ∃ positive constants c1, c2, and n0,
such that ∀n ≥ n0, 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n)}

 Is 3n3 ∈ Θ(n4) ??
 How about 22n∈ Θ(2n)??

Comp 122
O-notation
For function g(n), we define O(g(n)),
big-O of n, as the set:
O(g(n)) = {f(n) :
∃ positive constants c and n0,
such that ∀n ≥ n0,
we have 0 ≤ f(n) ≤ cg(n) }

Intuitively: Set of all functions
whose rate of growth is the same as
or lower than that of g(n).

g(n) is an asymptotic upper bound for f(n).

f(n) = Θ(g(n)) ⇒ f(n) = O(g(n)).
Θ(g(n)) ⊂ O(g(n)).
ymp - 8
Comp 122
Examples
O(g(n)) = {f(n) : ∃ positive constants c and n0,
such that ∀n ≥ n0, we have 0 ≤ f(n) ≤ cg(n) }

 Any linear function an + b is in O(n2). How?
 Show that 3n3=O(n4) for appropriate c and n0.

ymp - 9

Comp 122
Ω -notation
For function g(n), we define Ω(g(n)),
big-Omega of n, as the set:
Ω(g(n)) = {f(n) :
∃ positive constants c and n0,
such that ∀n ≥ n0,
we have 0 ≤ cg(n) ≤ f(n)}

Intuitively: Set of all functions
whose rate of growth is the same
as or higher than that of g(n).

g(n) is an asymptotic lower bound for f(n).

ymp - 10

f(n) = Θ(g(n)) ⇒ f(n) = Ω(g(n)).
Θ(g(n)) ⊂ Ω(g(n)).
Comp 122
Example
Ω(g(n)) = {f(n) : ∃ positive constants c and n0, such
that ∀n ≥ n0, we have 0 ≤ cg(n) ≤ f(n)}

 √n = Ω(lg n). Choose c and n0.

ymp - 11

Comp 122
ymp - 12

Relations Between Θ, O, Ω

Comp 122
Relations Between Θ, Ω, O
Theorem :: For any two functions g(n) and f(n),
Theorem For any two functions g(n) and f(n),
f(n) = Θ(g(n)) iff
f(n) = Θ(g(n)) iff
f(n) = O(g(n)) and f(n) = Ω(g(n)).
f(n) = O(g(n)) and f(n) = Ω(g(n)).

 I.e., Θ(g(n)) = O(g(n)) ∩ Ω(g(n))
 In practice, asymptotically tight bounds are
obtained from asymptotic upper and lower bounds.

ymp - 13

Comp 122
ymp - 14

Running Times
 “Running time is O(f(n))” ⇒ Worst case is O(f(n))
 O(f(n)) bound on the worst-case running time ⇒
O(f(n)) bound on the running time of every input.
 Θ(f(n)) bound on the worst-case running time ⇒
Θ(f(n)) bound on the running time of every input.
 “Running time is Ω(f(n))” ⇒ Best case is Ω(f(n))
 Can still say “Worst-case running time is Ω(f(n))”
 Means worst-case running time is given by some
unspecified function g(n) ∈ Ω(f(n)).
Comp 122
ymp - 15

Example
 Insertion sort takes Θ(n2) in the worst case, so
sorting (as a problem) is O(n2). Why?
 Any sort algorithm must look at each item, so
sorting is Ω(n).
 In fact, using (e.g.) merge sort, sorting is Θ(n lg n)
in the worst case.
 Later, we will prove that we cannot hope that any
comparison sort to do better in the worst case.
Comp 122
ymp - 16

Asymptotic Notation in Equations
 Can use asymptotic notation in equations to
replace expressions containing lower-order terms.
 For example,
4n3 + 3n2 + 2n + 1 = 4n3 + 3n2 + Θ(n)
= 4n3 + Θ(n2) = Θ(n3). How to interpret?
 In equations, Θ(f(n)) always stands for an
anonymous function g(n) ∈ Θ(f(n))
 In the example above, Θ(n2) stands for
3n2 + 2n + 1.

Comp 122
o-notation
For a given function g(n), the set little-o:
o(g(n)) = {f(n): ∀ c > 0, ∃ n0 > 0 such that
∀ n ≥ n0, we have 0 ≤ f(n) < cg(n)}.
f(n) becomes insignificant relative to g(n) as n
approaches infinity:

lim [f(n) / g(n)] = 0
n→∞

g(n) is an upper bound for f(n) that is not
asymptotically tight.
Observe the difference in this definition from previous
ones. Why?

ymp - 17

Comp 122
ω -notation
For a given function g(n), the set little-omega:

ω(g(n)) = {f(n): ∀ c > 0, ∃ n

> 0 such that
∀ n ≥ n0, we have 0 ≤ cg(n) < f(n)}.
0

f(n) becomes arbitrarily large relative to g(n) as n
approaches infinity:

lim [f(n) / g(n)] = ∞.

n→∞

g(n) is a lower bound for f(n) that is not
asymptotically tight.

ymp - 18

Comp 122
ymp - 19

Comparison of Functions
f↔g ≈ a↔b
f (n) = O(g(n)) ≈ a ≤ b
f (n) = Ω(g(n)) ≈ a ≥ b
f (n) = Θ(g(n)) ≈ a = b
f (n) = o(g(n)) ≈ a < b
f (n) = ω (g(n)) ≈ a > b

Comp 122
ymp - 20

Limits
 lim [f(n) / g(n)] = 0 ⇒ f(n) ∈ ο(g(n))
n→∞

 lim [f(n) / g(n)] < ∞ ⇒ f(n) ∈ Ο(g(n))
n→∞

 0 < lim [f(n) / g(n)] < ∞ ⇒ f(n) ∈ Θ(g(n))
n→∞

 0 < lim [f(n) / g(n)] ⇒ f(n) ∈ Ω(g(n))
n→∞

 lim [f(n) / g(n)] = ∞ ⇒ f(n) ∈ ω(g(n))
n→∞

 lim [f(n) / g(n)] undefined ⇒ can’t say
n→∞

Comp 122
ymp - 21

Properties
 Transitivity

f(n) = Θ(g(n)) & g(n) = Θ(h(n)) ⇒ f(n) = Θ(h(n))
f(n) = O(g(n)) & g(n) = O(h(n)) ⇒ f(n) = O(h(n))
f(n) = Ω(g(n)) & g(n) = Ω(h(n)) ⇒ f(n) = Ω(h(n))
f(n) = o (g(n)) & g(n) = o (h(n)) ⇒ f(n) = o (h(n))
f(n) = ω(g(n)) & g(n) = ω(h(n)) ⇒ f(n) = ω(h(n))

 Reflexivity
f(n) = Θ(f(n))
f(n) = O(f(n))
f(n) = Ω(f(n))

Comp 122
ymp - 22

Properties
 Symmetry
f(n) = Θ(g(n)) iff g(n) = Θ(f(n))
 Complementarity
f(n) = O(g(n)) iff g(n) = Ω(f(n))
f(n) = o(g(n)) iff g(n) = ω((f(n))

Comp 122
Common Functions

December 20, 2013

Comp 122, Spring 2004
Monotonicity
 f(n) is

ymp - 24






monotonically increasing if m ≤ n ⇒ f(m) ≤ f(n).
monotonically decreasing if m ≥ n ⇒ f(m) ≥ f(n).
strictly increasing if m < n ⇒ f(m) < f(n).
strictly decreasing if m > n ⇒ f(m) > f(n).

Comp 122
Exponentials
 Useful Identities:
1
a =
a
(a m ) n = a mn
−1

a m a n = a m+ n

 Exponentials and polynomials

ymp - 25

nb
lim n = 0
n→∞ a
⇒ n b = o( a n )
Comp 122
Logarithms
x = logba is the
exponent for a = bx.

a = b logb a
log c (ab) = log c a + log c b
log b a = n log b a
n

Natural log: ln a = logea
Binary log: lg a = log2a

lg2a = (lg a)2
lg lg a = lg (lg a)

ymp - 26

log c a
log b a =
log c b
log b (1 / a ) = − log b a
1
log b a =
log a b
a logb c = c logb a
Comp 122
Logarithms and exponentials – Bases
 If the base of a logarithm is changed from one
constant to another, the value is altered by a
constant factor.
 Ex: log10 n * log210 = log2 n.
 Base of logarithm is not an issue in asymptotic
notation.

 Exponentials with different bases differ by a
exponential factor (not a constant factor).

ymp - 27

 Ex: 2n = (2/3)n*3n.
Comp 122
Polylogarithms
 For a ≥ 0, b > 0, lim n→∞ ( lga n / nb ) = 0,
so lga n = o(nb), and nb = ω(lga n )
 Prove using L’Hopital’s rule repeatedly

 lg(n!) = Θ(n lg n)

ymp - 28

 Prove using Stirling’s approximation (in the text) for lg(n!).

Comp 122
Exercise
Express functions in A in asymptotic notation using functions in B.

ymp - 29

A
5n2 + 100n

B
3n2 + 2

A ∈ Θ(B)

A ∈ Θ(n2), n2 ∈ Θ(B) ⇒ A ∈ Θ(B)

log3(n2)

log2(n3)

A ∈ Θ(B)

logba = logca / logcb; A = 2lgn / lg3, B = 3lgn, A/B =2/(3lg3)
A ∈ ω (B)
nlg4
3lg n
alog b = blog a; B =3lg n=nlg 3; A/B =nlg(4/3) → ∞ as n→∞
A ∈ ο (B)
lg2n
n1/2
lim ( lga n / nb ) = 0 (here a = 2 and b = 1/2) ⇒ A ∈ ο (B)
n→∞

Comp 122
Summations – Review

December 20, 2013

Comp 122, Spring 2004
ymp - 31

Review on Summations
 Why do we need summation formulas?
For computing the running times of iterative
constructs (loops). (CLRS – Appendix A)
Example: Maximum Subvector
Given an array A[1…n] of numeric values (can be
positive, zero, and negative) determine the
subvector A[i…j] (1≤ i ≤ j ≤ n) whose sum of
elements is maximum over all subvectors.
1

-2

2
Comp 122

2
Review on Summations
MaxSubvector(A, n)
maxsum ← 0;
for i ← 1 to n
do for j = i to n
sum ← 0
for k ← i to j
do sum += A[k]
maxsum ← max(sum, maxsum)
return maxsum
n

n

j

T(n) = ∑ ∑ ∑ 1
i=1 j=i k=i

NOTE: This is not a simplified solution. What is the final answer?

ymp - 32

Comp 122
Review on Summations
 Constant Series: For integers a and b, a ≤ b,
b

∑1 = b − a + 1
i =a

 Linear Series (Arithmetic Series): For n ≥ 0,
n
n(n + 1)
∑ i = 1 + 2 + + n = 2
i =1
n
 Quadratic Series: For n 2≥ 0, 2 n(n + 1)(2n + 1)
i 2 = 12 + 2 +  + n =

ymp - 33

∑

6

i =1

Comp 122
ymp - 34

Review on Summations
 Cubic Series: For n ≥ 0,
n 2 (n + 1) 2
i 3 = 13 + 23 +  + n 3 =
∑
4
i =1
n

 Geometric Series: For real x ≠ 1,

x n+1 − 1
xk = 1+ x + x2 +  + xn =
∑
x −1
k =0
n

For |x| < 1,

∞

1
∑ x = 1− x
k =0
k

Comp 122
ymp - 35

Review on Summations
 Linear-Geometric Series: For n ≥ 0, real c ≠ 1,
n +1

− (n + 1)c + nc
∑ ic = c + 2c +  + nc =
(c − 1) 2
i =1
n

i

2

n

 Harmonic Series: nth harmonic number, n∈I+,
1 1
1
Hn = 1+ + ++
2 3
n
n

1
= ∑ = ln(n) + O(1)
k =1 k
Comp 122

n+ 2

+c
Review on Summations
 Telescoping Series:
n

∑a
k =1

k

− ak −1 = an − a0

 Differentiating Series: For |x| < 1,

ymp - 36

∞

x
∑ kx = (1 − x ) 2
k =0
k

Comp 122
Review on Summations
 Approximation by integrals:
 For monotonically increasing f(n)
n

∫

m−1

n

n +1

k =m

m

f ( x)dx ≤ ∑ f (k ) ≤

∫ f ( x)dx

 For monotonically decreasing f(n)
n +1

∫

m

n

f ( x)dx ≤ ∑ f (k ) ≤
k =m

n

∫ f ( x)dx

m−1

 How?

ymp - 37

Comp 122
Review on Summations
 nth harmonic number

ymp - 38

n

1
∑k ≥
k =1

n+1

∫
1

dx
= ln(n + 1)
x

n

n

1
dx
≤ ∫ = ln n
∑k x
k =2
1
n

1
⇒ ∑ ≤ ln n + 1
k =1 k

Comp 122
Reading Assignment
 Chapter 4 of CLRS.

ymp - 39

Comp 122

Mais conteúdo relacionado

Mais procurados

Mais procurados (19)

Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Time complexity
Time complexityTime complexity
Time complexity
 
Time complexity
Time complexityTime complexity
Time complexity
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Basics & asymptotic notations
Basics & asymptotic notationsBasics & asymptotic notations
Basics & asymptotic notations
 
Recurrences
RecurrencesRecurrences
Recurrences
 
Clase3 Notacion
Clase3 NotacionClase3 Notacion
Clase3 Notacion
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Algorithum Analysis
Algorithum AnalysisAlgorithum Analysis
Algorithum Analysis
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
 
Asymptotic notations(Big O, Omega, Theta )
Asymptotic notations(Big O, Omega, Theta )Asymptotic notations(Big O, Omega, Theta )
Asymptotic notations(Big O, Omega, Theta )
 
Slide2
Slide2Slide2
Slide2
 
Recurrences
RecurrencesRecurrences
Recurrences
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexity
 
RECURRENCE EQUATIONS & ANALYZING THEM
RECURRENCE EQUATIONS & ANALYZING THEMRECURRENCE EQUATIONS & ANALYZING THEM
RECURRENCE EQUATIONS & ANALYZING THEM
 
Computational Complexity
Computational ComplexityComputational Complexity
Computational Complexity
 
Recurrences
RecurrencesRecurrences
Recurrences
 

Destaque

Lec2 Algorth
Lec2 AlgorthLec2 Algorth
Lec2 Algorthhumanist3
 
CS Fundamentals: Scalability and Memory
CS Fundamentals: Scalability and MemoryCS Fundamentals: Scalability and Memory
CS Fundamentals: Scalability and MemoryHaseeb Qureshi
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihmSajid Marwat
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAmrinder Arora
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexityAnkit Katiyar
 

Destaque (8)

Lec2 Algorth
Lec2 AlgorthLec2 Algorth
Lec2 Algorth
 
Lecture1
Lecture1Lecture1
Lecture1
 
big_oh
big_ohbig_oh
big_oh
 
CS Fundamentals: Scalability and Memory
CS Fundamentals: Scalability and MemoryCS Fundamentals: Scalability and Memory
CS Fundamentals: Scalability and Memory
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 

Semelhante a 02 asymp

Lecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfLecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfShaistaRiaz4
 
Design and analysis of algorithm ppt ppt
Design and analysis of algorithm ppt pptDesign and analysis of algorithm ppt ppt
Design and analysis of algorithm ppt pptsrushtiivp
 
2-AnalysisOfAlgs.ppt
2-AnalysisOfAlgs.ppt2-AnalysisOfAlgs.ppt
2-AnalysisOfAlgs.pptTahseenEjaz3
 
Lecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).pptLecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).pptZohairMughal1
 
Lecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.pptLecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.pptZohairMughal1
 
Skiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationSkiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationzukun
 
2_Asymptotic notations.pptx
2_Asymptotic notations.pptx2_Asymptotic notations.pptx
2_Asymptotic notations.pptxdattakumar4
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfAmayJaiswal4
 
Dr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabistDr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabistGatewayggg Testeru
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Deepak John
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquerKrish_ver2
 
02 asymptotic notations
02 asymptotic notations02 asymptotic notations
02 asymptotic notationsTarikuDabala1
 

Semelhante a 02 asymp (20)

Asymtotic Appoach.ppt
Asymtotic Appoach.pptAsymtotic Appoach.ppt
Asymtotic Appoach.ppt
 
02-asymp.ppt
02-asymp.ppt02-asymp.ppt
02-asymp.ppt
 
Lecture3(b).pdf
Lecture3(b).pdfLecture3(b).pdf
Lecture3(b).pdf
 
DAA_LECT_2.pdf
DAA_LECT_2.pdfDAA_LECT_2.pdf
DAA_LECT_2.pdf
 
Lecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfLecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdf
 
Design and analysis of algorithm ppt ppt
Design and analysis of algorithm ppt pptDesign and analysis of algorithm ppt ppt
Design and analysis of algorithm ppt ppt
 
2-AnalysisOfAlgs.ppt
2-AnalysisOfAlgs.ppt2-AnalysisOfAlgs.ppt
2-AnalysisOfAlgs.ppt
 
Lecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).pptLecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).ppt
 
Lecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.pptLecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.ppt
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Time complexity
Time complexityTime complexity
Time complexity
 
Skiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationSkiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notation
 
2_Asymptotic notations.pptx
2_Asymptotic notations.pptx2_Asymptotic notations.pptx
2_Asymptotic notations.pptx
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
 
Dr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabistDr hasany 2467_16649_1_lec-2-zabist
Dr hasany 2467_16649_1_lec-2-zabist
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
03 dc
03 dc03 dc
03 dc
 
02 asymptotic notations
02 asymptotic notations02 asymptotic notations
02 asymptotic notations
 

Último

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Último (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

02 asymp

  • 1. Asymptotic Notation, Asymptotic Notation, Review of Functions & Review of Functions & Summations Summations December 20, 2013 Comp 122, Spring 2004
  • 2. Asymptotic Complexity  Running time of an algorithm as a function of input size n for large n.  Expressed using only the highest-order term in the expression for the exact running time.  Instead of exact running time, say Θ(n2).  Describes behavior of function in the limit.  Written using Asymptotic Notation. ymp - 2 Comp 122
  • 3. ymp - 3 Asymptotic Notation  Θ, O, Ω, o, ω  Defined for functions over the natural numbers.  Ex: f(n) = Θ(n2).  Describes how f(n) grows in comparison to n2.  Define a set of functions; in practice used to compare two function sizes.  The notations describe different rate-of-growth relations between the defining function and the defined set of functions. Comp 122
  • 4. Θ-notation For function g(n), we define Θ(g(n)), big-Theta of n, as the set: Θ(g(n)) = {f(n) : ∃ positive constants c1, c2, and n0, such that ∀n ≥ n0, we have 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n) } Intuitively: Set of all functions that have the same rate of growth as g(n). g(n) is an asymptotically tight bound for f(n). ymp - 4 Comp 122
  • 5. Θ-notation For function g(n), we define Θ(g(n)), big-Theta of n, as the set: Θ(g(n)) = {f(n) : ∃ positive constants c1, c2, and n0, such that ∀n ≥ n0, we have 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n) } Technically, f(n) ∈ Θ(g(n)). Older usage, f(n) = Θ(g(n)). I’ll accept either… f(n) and g(n) are nonnegative, for large n. ymp - 5 Comp 122
  • 6. ymp - 6 Example Θ(g(n)) = {f(n) : ∃ positive constants c1, c2, and n0, such that ∀n ≥ n0, 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n)}  10n2 - 3n = Θ(n2)  What constants for n0, c1, and c2 will work?  Make c1 a little smaller than the leading coefficient, and c2 a little bigger.  To compare orders of growth, look at the leading term.  Exercise: Prove that n2/2-3n= Θ(n2) Comp 122
  • 7. ymp - 7 Example Θ(g(n)) = {f(n) : ∃ positive constants c1, c2, and n0, such that ∀n ≥ n0, 0 ≤ c1g(n) ≤ f(n) ≤ c2g(n)}  Is 3n3 ∈ Θ(n4) ??  How about 22n∈ Θ(2n)?? Comp 122
  • 8. O-notation For function g(n), we define O(g(n)), big-O of n, as the set: O(g(n)) = {f(n) : ∃ positive constants c and n0, such that ∀n ≥ n0, we have 0 ≤ f(n) ≤ cg(n) } Intuitively: Set of all functions whose rate of growth is the same as or lower than that of g(n). g(n) is an asymptotic upper bound for f(n). f(n) = Θ(g(n)) ⇒ f(n) = O(g(n)). Θ(g(n)) ⊂ O(g(n)). ymp - 8 Comp 122
  • 9. Examples O(g(n)) = {f(n) : ∃ positive constants c and n0, such that ∀n ≥ n0, we have 0 ≤ f(n) ≤ cg(n) }  Any linear function an + b is in O(n2). How?  Show that 3n3=O(n4) for appropriate c and n0. ymp - 9 Comp 122
  • 10. Ω -notation For function g(n), we define Ω(g(n)), big-Omega of n, as the set: Ω(g(n)) = {f(n) : ∃ positive constants c and n0, such that ∀n ≥ n0, we have 0 ≤ cg(n) ≤ f(n)} Intuitively: Set of all functions whose rate of growth is the same as or higher than that of g(n). g(n) is an asymptotic lower bound for f(n). ymp - 10 f(n) = Θ(g(n)) ⇒ f(n) = Ω(g(n)). Θ(g(n)) ⊂ Ω(g(n)). Comp 122
  • 11. Example Ω(g(n)) = {f(n) : ∃ positive constants c and n0, such that ∀n ≥ n0, we have 0 ≤ cg(n) ≤ f(n)}  √n = Ω(lg n). Choose c and n0. ymp - 11 Comp 122
  • 12. ymp - 12 Relations Between Θ, O, Ω Comp 122
  • 13. Relations Between Θ, Ω, O Theorem :: For any two functions g(n) and f(n), Theorem For any two functions g(n) and f(n), f(n) = Θ(g(n)) iff f(n) = Θ(g(n)) iff f(n) = O(g(n)) and f(n) = Ω(g(n)). f(n) = O(g(n)) and f(n) = Ω(g(n)).  I.e., Θ(g(n)) = O(g(n)) ∩ Ω(g(n))  In practice, asymptotically tight bounds are obtained from asymptotic upper and lower bounds. ymp - 13 Comp 122
  • 14. ymp - 14 Running Times  “Running time is O(f(n))” ⇒ Worst case is O(f(n))  O(f(n)) bound on the worst-case running time ⇒ O(f(n)) bound on the running time of every input.  Θ(f(n)) bound on the worst-case running time ⇒ Θ(f(n)) bound on the running time of every input.  “Running time is Ω(f(n))” ⇒ Best case is Ω(f(n))  Can still say “Worst-case running time is Ω(f(n))”  Means worst-case running time is given by some unspecified function g(n) ∈ Ω(f(n)). Comp 122
  • 15. ymp - 15 Example  Insertion sort takes Θ(n2) in the worst case, so sorting (as a problem) is O(n2). Why?  Any sort algorithm must look at each item, so sorting is Ω(n).  In fact, using (e.g.) merge sort, sorting is Θ(n lg n) in the worst case.  Later, we will prove that we cannot hope that any comparison sort to do better in the worst case. Comp 122
  • 16. ymp - 16 Asymptotic Notation in Equations  Can use asymptotic notation in equations to replace expressions containing lower-order terms.  For example, 4n3 + 3n2 + 2n + 1 = 4n3 + 3n2 + Θ(n) = 4n3 + Θ(n2) = Θ(n3). How to interpret?  In equations, Θ(f(n)) always stands for an anonymous function g(n) ∈ Θ(f(n))  In the example above, Θ(n2) stands for 3n2 + 2n + 1. Comp 122
  • 17. o-notation For a given function g(n), the set little-o: o(g(n)) = {f(n): ∀ c > 0, ∃ n0 > 0 such that ∀ n ≥ n0, we have 0 ≤ f(n) < cg(n)}. f(n) becomes insignificant relative to g(n) as n approaches infinity: lim [f(n) / g(n)] = 0 n→∞ g(n) is an upper bound for f(n) that is not asymptotically tight. Observe the difference in this definition from previous ones. Why? ymp - 17 Comp 122
  • 18. ω -notation For a given function g(n), the set little-omega: ω(g(n)) = {f(n): ∀ c > 0, ∃ n > 0 such that ∀ n ≥ n0, we have 0 ≤ cg(n) < f(n)}. 0 f(n) becomes arbitrarily large relative to g(n) as n approaches infinity: lim [f(n) / g(n)] = ∞. n→∞ g(n) is a lower bound for f(n) that is not asymptotically tight. ymp - 18 Comp 122
  • 19. ymp - 19 Comparison of Functions f↔g ≈ a↔b f (n) = O(g(n)) ≈ a ≤ b f (n) = Ω(g(n)) ≈ a ≥ b f (n) = Θ(g(n)) ≈ a = b f (n) = o(g(n)) ≈ a < b f (n) = ω (g(n)) ≈ a > b Comp 122
  • 20. ymp - 20 Limits  lim [f(n) / g(n)] = 0 ⇒ f(n) ∈ ο(g(n)) n→∞  lim [f(n) / g(n)] < ∞ ⇒ f(n) ∈ Ο(g(n)) n→∞  0 < lim [f(n) / g(n)] < ∞ ⇒ f(n) ∈ Θ(g(n)) n→∞  0 < lim [f(n) / g(n)] ⇒ f(n) ∈ Ω(g(n)) n→∞  lim [f(n) / g(n)] = ∞ ⇒ f(n) ∈ ω(g(n)) n→∞  lim [f(n) / g(n)] undefined ⇒ can’t say n→∞ Comp 122
  • 21. ymp - 21 Properties  Transitivity f(n) = Θ(g(n)) & g(n) = Θ(h(n)) ⇒ f(n) = Θ(h(n)) f(n) = O(g(n)) & g(n) = O(h(n)) ⇒ f(n) = O(h(n)) f(n) = Ω(g(n)) & g(n) = Ω(h(n)) ⇒ f(n) = Ω(h(n)) f(n) = o (g(n)) & g(n) = o (h(n)) ⇒ f(n) = o (h(n)) f(n) = ω(g(n)) & g(n) = ω(h(n)) ⇒ f(n) = ω(h(n))  Reflexivity f(n) = Θ(f(n)) f(n) = O(f(n)) f(n) = Ω(f(n)) Comp 122
  • 22. ymp - 22 Properties  Symmetry f(n) = Θ(g(n)) iff g(n) = Θ(f(n))  Complementarity f(n) = O(g(n)) iff g(n) = Ω(f(n)) f(n) = o(g(n)) iff g(n) = ω((f(n)) Comp 122
  • 23. Common Functions December 20, 2013 Comp 122, Spring 2004
  • 24. Monotonicity  f(n) is ymp - 24     monotonically increasing if m ≤ n ⇒ f(m) ≤ f(n). monotonically decreasing if m ≥ n ⇒ f(m) ≥ f(n). strictly increasing if m < n ⇒ f(m) < f(n). strictly decreasing if m > n ⇒ f(m) > f(n). Comp 122
  • 25. Exponentials  Useful Identities: 1 a = a (a m ) n = a mn −1 a m a n = a m+ n  Exponentials and polynomials ymp - 25 nb lim n = 0 n→∞ a ⇒ n b = o( a n ) Comp 122
  • 26. Logarithms x = logba is the exponent for a = bx. a = b logb a log c (ab) = log c a + log c b log b a = n log b a n Natural log: ln a = logea Binary log: lg a = log2a lg2a = (lg a)2 lg lg a = lg (lg a) ymp - 26 log c a log b a = log c b log b (1 / a ) = − log b a 1 log b a = log a b a logb c = c logb a Comp 122
  • 27. Logarithms and exponentials – Bases  If the base of a logarithm is changed from one constant to another, the value is altered by a constant factor.  Ex: log10 n * log210 = log2 n.  Base of logarithm is not an issue in asymptotic notation.  Exponentials with different bases differ by a exponential factor (not a constant factor). ymp - 27  Ex: 2n = (2/3)n*3n. Comp 122
  • 28. Polylogarithms  For a ≥ 0, b > 0, lim n→∞ ( lga n / nb ) = 0, so lga n = o(nb), and nb = ω(lga n )  Prove using L’Hopital’s rule repeatedly  lg(n!) = Θ(n lg n) ymp - 28  Prove using Stirling’s approximation (in the text) for lg(n!). Comp 122
  • 29. Exercise Express functions in A in asymptotic notation using functions in B. ymp - 29 A 5n2 + 100n B 3n2 + 2 A ∈ Θ(B) A ∈ Θ(n2), n2 ∈ Θ(B) ⇒ A ∈ Θ(B) log3(n2) log2(n3) A ∈ Θ(B) logba = logca / logcb; A = 2lgn / lg3, B = 3lgn, A/B =2/(3lg3) A ∈ ω (B) nlg4 3lg n alog b = blog a; B =3lg n=nlg 3; A/B =nlg(4/3) → ∞ as n→∞ A ∈ ο (B) lg2n n1/2 lim ( lga n / nb ) = 0 (here a = 2 and b = 1/2) ⇒ A ∈ ο (B) n→∞ Comp 122
  • 30. Summations – Review December 20, 2013 Comp 122, Spring 2004
  • 31. ymp - 31 Review on Summations  Why do we need summation formulas? For computing the running times of iterative constructs (loops). (CLRS – Appendix A) Example: Maximum Subvector Given an array A[1…n] of numeric values (can be positive, zero, and negative) determine the subvector A[i…j] (1≤ i ≤ j ≤ n) whose sum of elements is maximum over all subvectors. 1 -2 2 Comp 122 2
  • 32. Review on Summations MaxSubvector(A, n) maxsum ← 0; for i ← 1 to n do for j = i to n sum ← 0 for k ← i to j do sum += A[k] maxsum ← max(sum, maxsum) return maxsum n n j T(n) = ∑ ∑ ∑ 1 i=1 j=i k=i NOTE: This is not a simplified solution. What is the final answer? ymp - 32 Comp 122
  • 33. Review on Summations  Constant Series: For integers a and b, a ≤ b, b ∑1 = b − a + 1 i =a  Linear Series (Arithmetic Series): For n ≥ 0, n n(n + 1) ∑ i = 1 + 2 + + n = 2 i =1 n  Quadratic Series: For n 2≥ 0, 2 n(n + 1)(2n + 1) i 2 = 12 + 2 +  + n = ymp - 33 ∑ 6 i =1 Comp 122
  • 34. ymp - 34 Review on Summations  Cubic Series: For n ≥ 0, n 2 (n + 1) 2 i 3 = 13 + 23 +  + n 3 = ∑ 4 i =1 n  Geometric Series: For real x ≠ 1, x n+1 − 1 xk = 1+ x + x2 +  + xn = ∑ x −1 k =0 n For |x| < 1, ∞ 1 ∑ x = 1− x k =0 k Comp 122
  • 35. ymp - 35 Review on Summations  Linear-Geometric Series: For n ≥ 0, real c ≠ 1, n +1 − (n + 1)c + nc ∑ ic = c + 2c +  + nc = (c − 1) 2 i =1 n i 2 n  Harmonic Series: nth harmonic number, n∈I+, 1 1 1 Hn = 1+ + ++ 2 3 n n 1 = ∑ = ln(n) + O(1) k =1 k Comp 122 n+ 2 +c
  • 36. Review on Summations  Telescoping Series: n ∑a k =1 k − ak −1 = an − a0  Differentiating Series: For |x| < 1, ymp - 36 ∞ x ∑ kx = (1 − x ) 2 k =0 k Comp 122
  • 37. Review on Summations  Approximation by integrals:  For monotonically increasing f(n) n ∫ m−1 n n +1 k =m m f ( x)dx ≤ ∑ f (k ) ≤ ∫ f ( x)dx  For monotonically decreasing f(n) n +1 ∫ m n f ( x)dx ≤ ∑ f (k ) ≤ k =m n ∫ f ( x)dx m−1  How? ymp - 37 Comp 122
  • 38. Review on Summations  nth harmonic number ymp - 38 n 1 ∑k ≥ k =1 n+1 ∫ 1 dx = ln(n + 1) x n n 1 dx ≤ ∫ = ln n ∑k x k =2 1 n 1 ⇒ ∑ ≤ ln n + 1 k =1 k Comp 122
  • 39. Reading Assignment  Chapter 4 of CLRS. ymp - 39 Comp 122