SlideShare a Scribd company logo
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

More Related Content

What's hot

Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
Rajandeep Gill
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 
Time complexity
Time complexityTime complexity
Time complexity
Kartik Chandra Mandal
 
Time complexity
Time complexityTime complexity
Time complexity
Katang Isip
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
Rishabh Soni
 
Basics & asymptotic notations
Basics & asymptotic notationsBasics & asymptotic notations
Basics & asymptotic notations
Rajendran
 
Recurrences
RecurrencesRecurrences
Recurrences
DEVTYPE
 
Clase3 Notacion
Clase3 NotacionClase3 Notacion
Clase3 Notacion
luzenith_g
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
Lovely Professional University
 
Asymptotic notations(Big O, Omega, Theta )
Asymptotic notations(Big O, Omega, Theta )Asymptotic notations(Big O, Omega, Theta )
Asymptotic notations(Big O, Omega, Theta )
swapnac12
 
Lec03 04-time complexity
Lec03 04-time complexityLec03 04-time complexity
Lec03 04-time complexityAbbas Ali
 
RECURRENCE EQUATIONS & ANALYZING THEM
RECURRENCE EQUATIONS & ANALYZING THEMRECURRENCE EQUATIONS & ANALYZING THEM
RECURRENCE EQUATIONS & ANALYZING THEM
Alpana Ingale
 
Recurrences
RecurrencesRecurrences

What's hot (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
 

Viewers also liked

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 Memory
Haseeb 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 Structures
Amrinder Arora
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
Muhammad Muzammal
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexityAnkit Katiyar
 

Viewers also liked (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
 

Similar to 02 asymp

Asymtotic Appoach.ppt
Asymtotic Appoach.pptAsymtotic Appoach.ppt
Asymtotic Appoach.ppt
SherylArulini1
 
02-asymp.ppt
02-asymp.ppt02-asymp.ppt
02-asymp.ppt
AnikGhosh44
 
Lecture3(b).pdf
Lecture3(b).pdfLecture3(b).pdf
Lecture3(b).pdf
ShaistaRiaz4
 
DAA_LECT_2.pdf
DAA_LECT_2.pdfDAA_LECT_2.pdf
DAA_LECT_2.pdf
AryanSaini69
 
Lecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfLecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdf
ShaistaRiaz4
 
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
srushtiivp
 
2-AnalysisOfAlgs.ppt
2-AnalysisOfAlgs.ppt2-AnalysisOfAlgs.ppt
2-AnalysisOfAlgs.ppt
TahseenEjaz3
 
Lecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.pptLecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.ppt
ZohairMughal1
 
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
ZohairMughal1
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
S.Shayan Daneshvar
 
Time complexity
Time complexityTime complexity
Time complexity
LAKSHMITHARUN PONNAM
 
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.pptx
dattakumar4
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
AmayJaiswal4
 
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
Gatewayggg 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 1
Deepak John
 
03 dc
03 dc03 dc
03 dc
Hira Gul
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
Krish_ver2
 
02 asymptotic notations
02 asymptotic notations02 asymptotic notations
02 asymptotic notations
TarikuDabala1
 

Similar to 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.ppt
Lecture 4 - Growth of Functions.pptLecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.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
 
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
 
03 dc
03 dc03 dc
03 dc
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
02 asymptotic notations
02 asymptotic notations02 asymptotic notations
02 asymptotic notations
 

Recently uploaded

Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 

Recently uploaded (20)

Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 

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