SlideShare a Scribd company logo
22 January 2023 Comp 122, Spring 2004
Asymptotic Notation,
Review of Functions &
Summations
asymp - 1 Comp 122
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 Q(n2).
 Describes behavior of function in the limit.
 Written using Asymptotic Notation.
asymp - 2 Comp 122
Asymptotic Notation
 Q, O, W, o, w
 Defined for functions over the natural numbers.
 Ex: f(n) = Q(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.
asymp - 3 Comp 122
Q-notation
Q(g(n)) = {f(n) :
 positive constants c1, c2, and n0,
such that n  n0,
we have 0  c1g(n)  f(n)  c2g(n)
}
For function g(n), we define Q(g(n)),
big-Theta of n, as the set:
g(n) is an asymptotically tight bound for f(n).
Intuitively: Set of all functions that
have the same rate of growth as g(n).
asymp - 4 Comp 122
Q-notation
Q(g(n)) = {f(n) :
 positive constants c1, c2, and n0,
such that n  n0,
we have 0  c1g(n)  f(n)  c2g(n)
}
For function g(n), we define Q(g(n)),
big-Theta of n, as the set:
Technically, f(n)  Q(g(n)).
Older usage, f(n) = Q(g(n)).
I’ll accept either…
f(n) and g(n) are nonnegative, for large n.
asymp - 5 Comp 122
Example
 10n2 - 3n = Q(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= Q(n2)
Q(g(n)) = {f(n) :  positive constants c1, c2, and n0,
such that n  n0, 0  c1g(n)  f(n)  c2g(n)}
asymp - 6 Comp 122
Example
 Is 3n3  Q(n4) ??
 How about 22n Q(2n)??
Q(g(n)) = {f(n) :  positive constants c1, c2, and n0,
such that n  n0, 0  c1g(n)  f(n)  c2g(n)}
asymp - 7 Comp 122
O-notation
O(g(n)) = {f(n) :
 positive constants c and n0,
such that n  n0,
we have 0  f(n)  cg(n) }
For function g(n), we define O(g(n)),
big-O of n, as the set:
g(n) is an asymptotic upper bound for f(n).
Intuitively: Set of all functions
whose rate of growth is the same as
or lower than that of g(n).
f(n) = Q(g(n))  f(n) = O(g(n)).
Q(g(n))  O(g(n)).
asymp - 8 Comp 122
Examples
 Any linear function an + b is in O(n2). How?
 Show that 3n3=O(n4) for appropriate c and n0.
O(g(n)) = {f(n) :  positive constants c and n0,
such that n  n0, we have 0  f(n)  cg(n) }
asymp - 9 Comp 122
W -notation
g(n) is an asymptotic lower bound for f(n).
Intuitively: Set of all functions
whose rate of growth is the same
as or higher than that of g(n).
f(n) = Q(g(n))  f(n) = W(g(n)).
Q(g(n))  W(g(n)).
W(g(n)) = {f(n) :
 positive constants c and n0,
such that n  n0,
we have 0  cg(n)  f(n)}
For function g(n), we define W(g(n)),
big-Omega of n, as the set:
asymp - 10 Comp 122
Example
 n = W(lg n). Choose c and n0.
W(g(n)) = {f(n) :  positive constants c and n0, such
that n  n0, we have 0  cg(n)  f(n)}
asymp - 11 Comp 122
Relations Between Q, O, W
asymp - 12 Comp 122
Relations Between Q, W, O
 I.e., Q(g(n)) = O(g(n))  W(g(n))
 In practice, asymptotically tight bounds are
obtained from asymptotic upper and lower bounds.
Theorem : For any two functions g(n) and f(n),
f(n) = Q(g(n)) iff
f(n) = O(g(n)) and f(n) = W(g(n)).
asymp - 13 Comp 122
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.
 Q(f(n)) bound on the worst-case running time 
Q(f(n)) bound on the running time of every input.
 “Running time is W(f(n))”  Best case is W(f(n))
 Can still say “Worst-case running time is W(f(n))”
 Means worst-case running time is given by some
unspecified function g(n)  W(f(n)).
asymp - 14 Comp 122
Example
 Insertion sort takes Q(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 W(n).
 In fact, using (e.g.) merge sort, sorting is Q(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.
asymp - 15 Comp 122
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 + Q(n)
= 4n3 + Q(n2) = Q(n3). How to interpret?
 In equations, Q(f(n)) always stands for an
anonymous function g(n)  Q(f(n))
 In the example above, Q(n2) stands for
3n2 + 2n + 1.
asymp - 16 Comp 122
o-notation
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?
o(g(n)) = {f(n):  c > 0,  n0 > 0 such that
 n  n0, we have 0  f(n) < cg(n)}.
For a given function g(n), the set little-o:
asymp - 17 Comp 122
w(g(n)) = {f(n):  c > 0,  n0 > 0 such that
 n  n0, we have 0  cg(n) < f(n)}.
w -notation
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.
For a given function g(n), the set little-omega:
asymp - 18 Comp 122
Comparison of Functions
f  g  a  b
f (n) = O(g(n))  a  b
f (n) = W(g(n))  a  b
f (n) = Q(g(n))  a = b
f (n) = o(g(n))  a < b
f (n) = w (g(n))  a > b
asymp - 19 Comp 122
Limits
 lim [f(n) / g(n)] = 0  f(n)  o(g(n))
n
 lim [f(n) / g(n)] <   f(n)  O(g(n))
n
 0 < lim [f(n) / g(n)] <   f(n)  Q(g(n))
n
 0 < lim [f(n) / g(n)]  f(n)  W(g(n))
n
 lim [f(n) / g(n)] =   f(n)  w(g(n))
n
 lim [f(n) / g(n)] undefined  can’t say
n
asymp - 20 Comp 122
Properties
 Transitivity
f(n) = Q(g(n)) & g(n) = Q(h(n))  f(n) = Q(h(n))
f(n) = O(g(n)) & g(n) = O(h(n))  f(n) = O(h(n))
f(n) = W(g(n)) & g(n) = W(h(n))  f(n) = W(h(n))
f(n) = o (g(n)) & g(n) = o (h(n))  f(n) = o (h(n))
f(n) = w(g(n)) & g(n) = w(h(n))  f(n) = w(h(n))
 Reflexivity
f(n) = Q(f(n))
f(n) = O(f(n))
f(n) = W(f(n))
asymp - 21 Comp 122
Properties
 Symmetry
f(n) = Q(g(n)) iff g(n) = Q(f(n))
 Complementarity
f(n) = O(g(n)) iff g(n) = W(f(n))
f(n) = o(g(n)) iff g(n) = w((f(n))
22 January 2023 Comp 122, Spring 2004
Common Functions
asymp - 23 Comp 122
Monotonicity
 f(n) is
 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).
asymp - 24 Comp 122
Exponentials
 Useful Identities:
 Exponentials and polynomials
n
m
n
m
mn
n
m
a
a
a
a
a
a
a





)
(
1
1
)
(
0
lim
n
b
n
b
n
a
o
n
a
n





asymp - 25 Comp 122
Logarithms
x = logba is the
exponent for a = bx.
Natural log: ln a = logea
Binary log: lg a = log2a
lg2a = (lg a)2
lg lg a = lg (lg a)
a
c
a
b
b
b
c
c
b
b
n
b
c
c
c
a
b
b
b
c
a
b
a
a
a
b
a
a
a
n
a
b
a
ab
b
a
log
log
log
log
1
log
log
)
/
1
(
log
log
log
log
log
log
log
log
)
(
log









asymp - 26 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).
 Ex: 2n = (2/3)n*3n.
asymp - 27 Comp 122
Polylogarithms
 For a  0, b > 0, lim n ( lga n / nb ) = 0,
so lga n = o(nb), and nb = w(lga n )
 Prove using L’Hopital’s rule repeatedly
 lg(n!) = Q(n lg n)
 Prove using Stirling’s approximation (in the text) for lg(n!).
asymp - 28 Comp 122
Exercise
Express functions in A in asymptotic notation using functions in B.
A B
5n2 + 100n 3n2 + 2
A  Q(n2), n2  Q(B)  A  Q(B)
log3(n2) log2(n3)
logba = logca / logcb; A = 2lgn / lg3, B = 3lgn, A/B =2/(3lg3)
nlg4
3lg n
alog b = blog a; B =3lg n
=nlg 3
; A/B =nlg(4/3)
  as n
lg2n n1/2
lim ( lga n / nb ) = 0 (here a = 2 and b = 1/2)  A  o (B)
n
A  Q(B)
A  Q(B)
A  w(B)
A  o (B)
22 January 2023 Comp 122, Spring 2004
Summations – Review
asymp - 30 Comp 122
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 2
asymp - 31 Comp 122
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?
asymp - 32 Comp 122
Review on Summations
 Constant Series: For integers a and b, a  b,
 Linear Series (Arithmetic Series): For n  0,
 Quadratic Series: For n  0,





b
a
i
a
b 1
1
2
)
1
(
2
1
1








n
n
n
i
n
i










n
i
n
n
n
n
i
1
2
2
2
2
6
)
1
2
)(
1
(
2
1 
asymp - 33 Comp 122
Review on Summations
 Cubic Series: For n  0,
 Geometric Series: For real x  1,
For |x| < 1,








n
i
n
n
n
i
1
2
2
3
3
3
3
4
)
1
(
2
1 











n
k
n
n
k
x
x
x
x
x
x
0
1
2
1
1
1 


 

0 1
1
k
k
x
x
asymp - 34 Comp 122
Review on Summations
 Linear-Geometric Series: For n  0, real c  1,
 Harmonic Series: nth harmonic number, nI+,














n
i
n
n
n
i
c
c
nc
c
n
nc
c
c
ic
1
2
2
1
2
)
1
(
)
1
(
2 
n
Hn
1
3
1
2
1
1 



 





n
k
O
n
k
1
)
1
(
)
ln(
1
asymp - 35 Comp 122
Review on Summations
 Telescoping Series:
 Differentiating Series: For |x| < 1,


 


n
k
n
k
k a
a
a
a
1
0
1
 


 

0
2
1
k
k
x
x
kx
asymp - 36 Comp 122
Review on Summations
 Approximation by integrals:
 For monotonically increasing f(n)
 For monotonically decreasing f(n)
 How?
  
 



n
m
n
m
k
n
m
dx
x
f
k
f
dx
x
f
1
1
)
(
)
(
)
(
  

 


1
1
)
(
)
(
)
(
n
m
n
m
k
n
m
dx
x
f
k
f
dx
x
f
asymp - 37 Comp 122
Review on Summations
 nth harmonic number
 





n
k
n
n
x
dx
k
1
1
1
)
1
ln(
1
 



n
k
n
n
x
dx
k
2 1
ln
1





n
k
n
k
1
1
ln
1
asymp - 38 Comp 122
Reading Assignment
 Chapter 4 of CLRS.

More Related Content

Similar to 02-asymp.ppt

Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
Protap Mondal
 
Lecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfLecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdf
ShaistaRiaz4
 
Lecture 2 data structures and algorithms
Lecture 2 data structures and algorithmsLecture 2 data structures and algorithms
Lecture 2 data structures and algorithmsAakash deep Singhal
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
Rajandeep Gill
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 
02 asymptotic notations
02 asymptotic notations02 asymptotic notations
02 asymptotic notations
TarikuDabala1
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
mustafa sarac
 
1.algorithms
1.algorithms1.algorithms
1.algorithms
Chandan Singh
 
asymptotic notations i
asymptotic notations iasymptotic notations i
asymptotic notations i
Ali mahmood
 
Skiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationSkiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationzukun
 
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
 
How to design a linear control system
How to design a linear control systemHow to design a linear control system
How to design a linear control system
Alireza Mirzaei
 
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
 
AsymptoticAnalysis.ppt
AsymptoticAnalysis.pptAsymptoticAnalysis.ppt
AsymptoticAnalysis.ppt
SiddheshUpadhyay3
 
Time complexity
Time complexityTime complexity
Time complexity
LAKSHMITHARUN PONNAM
 
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
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
S.Shayan Daneshvar
 

Similar to 02-asymp.ppt (20)

Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Lecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdfLecture 3(a) Asymptotic-analysis.pdf
Lecture 3(a) Asymptotic-analysis.pdf
 
Lecture 2 data structures and algorithms
Lecture 2 data structures and algorithmsLecture 2 data structures and algorithms
Lecture 2 data structures and algorithms
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
02 asymptotic notations
02 asymptotic notations02 asymptotic notations
02 asymptotic notations
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
1.algorithms
1.algorithms1.algorithms
1.algorithms
 
asymptotic notations i
asymptotic notations iasymptotic notations i
asymptotic notations i
 
Skiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notationSkiena algorithm 2007 lecture02 asymptotic notation
Skiena algorithm 2007 lecture02 asymptotic notation
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.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
 
big_oh
big_ohbig_oh
big_oh
 
How to design a linear control system
How to design a linear control systemHow to design a linear control system
How to design a linear control system
 
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
 
AsymptoticAnalysis.ppt
AsymptoticAnalysis.pptAsymptoticAnalysis.ppt
AsymptoticAnalysis.ppt
 
Time complexity
Time complexityTime complexity
Time complexity
 
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
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 

Recently uploaded

Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
Roshan Dwivedi
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 

Recently uploaded (20)

Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Launch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in MinutesLaunch Your Streaming Platforms in Minutes
Launch Your Streaming Platforms in Minutes
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 

02-asymp.ppt

  • 1. 22 January 2023 Comp 122, Spring 2004 Asymptotic Notation, Review of Functions & Summations
  • 2. asymp - 1 Comp 122 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 Q(n2).  Describes behavior of function in the limit.  Written using Asymptotic Notation.
  • 3. asymp - 2 Comp 122 Asymptotic Notation  Q, O, W, o, w  Defined for functions over the natural numbers.  Ex: f(n) = Q(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.
  • 4. asymp - 3 Comp 122 Q-notation Q(g(n)) = {f(n) :  positive constants c1, c2, and n0, such that n  n0, we have 0  c1g(n)  f(n)  c2g(n) } For function g(n), we define Q(g(n)), big-Theta of n, as the set: g(n) is an asymptotically tight bound for f(n). Intuitively: Set of all functions that have the same rate of growth as g(n).
  • 5. asymp - 4 Comp 122 Q-notation Q(g(n)) = {f(n) :  positive constants c1, c2, and n0, such that n  n0, we have 0  c1g(n)  f(n)  c2g(n) } For function g(n), we define Q(g(n)), big-Theta of n, as the set: Technically, f(n)  Q(g(n)). Older usage, f(n) = Q(g(n)). I’ll accept either… f(n) and g(n) are nonnegative, for large n.
  • 6. asymp - 5 Comp 122 Example  10n2 - 3n = Q(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= Q(n2) Q(g(n)) = {f(n) :  positive constants c1, c2, and n0, such that n  n0, 0  c1g(n)  f(n)  c2g(n)}
  • 7. asymp - 6 Comp 122 Example  Is 3n3  Q(n4) ??  How about 22n Q(2n)?? Q(g(n)) = {f(n) :  positive constants c1, c2, and n0, such that n  n0, 0  c1g(n)  f(n)  c2g(n)}
  • 8. asymp - 7 Comp 122 O-notation O(g(n)) = {f(n) :  positive constants c and n0, such that n  n0, we have 0  f(n)  cg(n) } For function g(n), we define O(g(n)), big-O of n, as the set: g(n) is an asymptotic upper bound for f(n). Intuitively: Set of all functions whose rate of growth is the same as or lower than that of g(n). f(n) = Q(g(n))  f(n) = O(g(n)). Q(g(n))  O(g(n)).
  • 9. asymp - 8 Comp 122 Examples  Any linear function an + b is in O(n2). How?  Show that 3n3=O(n4) for appropriate c and n0. O(g(n)) = {f(n) :  positive constants c and n0, such that n  n0, we have 0  f(n)  cg(n) }
  • 10. asymp - 9 Comp 122 W -notation g(n) is an asymptotic lower bound for f(n). Intuitively: Set of all functions whose rate of growth is the same as or higher than that of g(n). f(n) = Q(g(n))  f(n) = W(g(n)). Q(g(n))  W(g(n)). W(g(n)) = {f(n) :  positive constants c and n0, such that n  n0, we have 0  cg(n)  f(n)} For function g(n), we define W(g(n)), big-Omega of n, as the set:
  • 11. asymp - 10 Comp 122 Example  n = W(lg n). Choose c and n0. W(g(n)) = {f(n) :  positive constants c and n0, such that n  n0, we have 0  cg(n)  f(n)}
  • 12. asymp - 11 Comp 122 Relations Between Q, O, W
  • 13. asymp - 12 Comp 122 Relations Between Q, W, O  I.e., Q(g(n)) = O(g(n))  W(g(n))  In practice, asymptotically tight bounds are obtained from asymptotic upper and lower bounds. Theorem : For any two functions g(n) and f(n), f(n) = Q(g(n)) iff f(n) = O(g(n)) and f(n) = W(g(n)).
  • 14. asymp - 13 Comp 122 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.  Q(f(n)) bound on the worst-case running time  Q(f(n)) bound on the running time of every input.  “Running time is W(f(n))”  Best case is W(f(n))  Can still say “Worst-case running time is W(f(n))”  Means worst-case running time is given by some unspecified function g(n)  W(f(n)).
  • 15. asymp - 14 Comp 122 Example  Insertion sort takes Q(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 W(n).  In fact, using (e.g.) merge sort, sorting is Q(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.
  • 16. asymp - 15 Comp 122 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 + Q(n) = 4n3 + Q(n2) = Q(n3). How to interpret?  In equations, Q(f(n)) always stands for an anonymous function g(n)  Q(f(n))  In the example above, Q(n2) stands for 3n2 + 2n + 1.
  • 17. asymp - 16 Comp 122 o-notation 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? o(g(n)) = {f(n):  c > 0,  n0 > 0 such that  n  n0, we have 0  f(n) < cg(n)}. For a given function g(n), the set little-o:
  • 18. asymp - 17 Comp 122 w(g(n)) = {f(n):  c > 0,  n0 > 0 such that  n  n0, we have 0  cg(n) < f(n)}. w -notation 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. For a given function g(n), the set little-omega:
  • 19. asymp - 18 Comp 122 Comparison of Functions f  g  a  b f (n) = O(g(n))  a  b f (n) = W(g(n))  a  b f (n) = Q(g(n))  a = b f (n) = o(g(n))  a < b f (n) = w (g(n))  a > b
  • 20. asymp - 19 Comp 122 Limits  lim [f(n) / g(n)] = 0  f(n)  o(g(n)) n  lim [f(n) / g(n)] <   f(n)  O(g(n)) n  0 < lim [f(n) / g(n)] <   f(n)  Q(g(n)) n  0 < lim [f(n) / g(n)]  f(n)  W(g(n)) n  lim [f(n) / g(n)] =   f(n)  w(g(n)) n  lim [f(n) / g(n)] undefined  can’t say n
  • 21. asymp - 20 Comp 122 Properties  Transitivity f(n) = Q(g(n)) & g(n) = Q(h(n))  f(n) = Q(h(n)) f(n) = O(g(n)) & g(n) = O(h(n))  f(n) = O(h(n)) f(n) = W(g(n)) & g(n) = W(h(n))  f(n) = W(h(n)) f(n) = o (g(n)) & g(n) = o (h(n))  f(n) = o (h(n)) f(n) = w(g(n)) & g(n) = w(h(n))  f(n) = w(h(n))  Reflexivity f(n) = Q(f(n)) f(n) = O(f(n)) f(n) = W(f(n))
  • 22. asymp - 21 Comp 122 Properties  Symmetry f(n) = Q(g(n)) iff g(n) = Q(f(n))  Complementarity f(n) = O(g(n)) iff g(n) = W(f(n)) f(n) = o(g(n)) iff g(n) = w((f(n))
  • 23. 22 January 2023 Comp 122, Spring 2004 Common Functions
  • 24. asymp - 23 Comp 122 Monotonicity  f(n) is  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).
  • 25. asymp - 24 Comp 122 Exponentials  Useful Identities:  Exponentials and polynomials n m n m mn n m a a a a a a a      ) ( 1 1 ) ( 0 lim n b n b n a o n a n     
  • 26. asymp - 25 Comp 122 Logarithms x = logba is the exponent for a = bx. Natural log: ln a = logea Binary log: lg a = log2a lg2a = (lg a)2 lg lg a = lg (lg a) a c a b b b c c b b n b c c c a b b b c a b a a a b a a a n a b a ab b a log log log log 1 log log ) / 1 ( log log log log log log log log ) ( log         
  • 27. asymp - 26 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).  Ex: 2n = (2/3)n*3n.
  • 28. asymp - 27 Comp 122 Polylogarithms  For a  0, b > 0, lim n ( lga n / nb ) = 0, so lga n = o(nb), and nb = w(lga n )  Prove using L’Hopital’s rule repeatedly  lg(n!) = Q(n lg n)  Prove using Stirling’s approximation (in the text) for lg(n!).
  • 29. asymp - 28 Comp 122 Exercise Express functions in A in asymptotic notation using functions in B. A B 5n2 + 100n 3n2 + 2 A  Q(n2), n2  Q(B)  A  Q(B) log3(n2) log2(n3) logba = logca / logcb; A = 2lgn / lg3, B = 3lgn, A/B =2/(3lg3) nlg4 3lg n alog b = blog a; B =3lg n =nlg 3 ; A/B =nlg(4/3)   as n lg2n n1/2 lim ( lga n / nb ) = 0 (here a = 2 and b = 1/2)  A  o (B) n A  Q(B) A  Q(B) A  w(B) A  o (B)
  • 30. 22 January 2023 Comp 122, Spring 2004 Summations – Review
  • 31. asymp - 30 Comp 122 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 2
  • 32. asymp - 31 Comp 122 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?
  • 33. asymp - 32 Comp 122 Review on Summations  Constant Series: For integers a and b, a  b,  Linear Series (Arithmetic Series): For n  0,  Quadratic Series: For n  0,      b a i a b 1 1 2 ) 1 ( 2 1 1         n n n i n i           n i n n n n i 1 2 2 2 2 6 ) 1 2 )( 1 ( 2 1 
  • 34. asymp - 33 Comp 122 Review on Summations  Cubic Series: For n  0,  Geometric Series: For real x  1, For |x| < 1,         n i n n n i 1 2 2 3 3 3 3 4 ) 1 ( 2 1             n k n n k x x x x x x 0 1 2 1 1 1       0 1 1 k k x x
  • 35. asymp - 34 Comp 122 Review on Summations  Linear-Geometric Series: For n  0, real c  1,  Harmonic Series: nth harmonic number, nI+,               n i n n n i c c nc c n nc c c ic 1 2 2 1 2 ) 1 ( ) 1 ( 2  n Hn 1 3 1 2 1 1            n k O n k 1 ) 1 ( ) ln( 1
  • 36. asymp - 35 Comp 122 Review on Summations  Telescoping Series:  Differentiating Series: For |x| < 1,       n k n k k a a a a 1 0 1        0 2 1 k k x x kx
  • 37. asymp - 36 Comp 122 Review on Summations  Approximation by integrals:  For monotonically increasing f(n)  For monotonically decreasing f(n)  How?         n m n m k n m dx x f k f dx x f 1 1 ) ( ) ( ) (         1 1 ) ( ) ( ) ( n m n m k n m dx x f k f dx x f
  • 38. asymp - 37 Comp 122 Review on Summations  nth harmonic number        n k n n x dx k 1 1 1 ) 1 ln( 1      n k n n x dx k 2 1 ln 1      n k n k 1 1 ln 1
  • 39. asymp - 38 Comp 122 Reading Assignment  Chapter 4 of CLRS.