SlideShare a Scribd company logo
Asymptotic Analysis
CLRS, Sections 3.1 – 3.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.
Describes behavior of function in the limit.
Written using Asymptotic Notation.
CS 321 - Data Structures 2
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.
Defines a set of functions; in practice used to
compare growth rate of two functions.
The notations describe the relationship between
the defining function and a defined set of
functions.
CS 321 - Data Structures 3
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))
CS 321 - Data Structures 4
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:
CS 321 - Data Structures 5
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).
CS 321 - Data Structures 6
Relationship Between Q, O, W
CS 321 - Data Structures 7
Relationship Between Q, W, O
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)).
CS 321 - Data Structures 8
o-notation
g(n) is an upper bound for f(n)that is not
asymptotically tight.
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:
Intuitively: Set of all functions whose rate of
growth is lower than that of g(n).
CS 321 - Data Structures 9
w(g(n)) = {f(n):  c > 0,  n0 > 0 such
that  n  n0, we have 0  cg(n) < f(n)}.
w -notation
g(n) is a lower bound for f(n) that is not
asymptotically tight.
For a given function g(n), the set little-omega:
Intuitively: Set of all functions whose rate of
growth is higher than that of g(n).
CS 321 - Data Structures 10
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
CS 321 - Data Structures 11
Limit Definitions of Asymptotic
Notations
o-notation (little-o):
– f(n) becomes insignificant relative to g(n) as n
approaches infinity:
lim [f(n) / g(n)] = 0
n
w -notation (little-omega):
– f(n) becomes arbitrarily large relative to g(n) as
n approaches infinity:
lim [f(n) / g(n)] = 
n
CS 321 - Data Structures 12
Limit Definitions of Asymptotic
Notations
Q-notation (Big-theta):
– f(n) relative to g(n)equals a constant, c, which is
greater than 0 and less than infinity as n approaches
infinity:
0 < lim [f(n) / g(n)] < 
n
CS 321 - Data Structures 13
Limit Definitions of Asymptotic
Notations
O-notation (Big-o):
– f(n)  O(g(n))  f(n)  Q(g(n))and f(n)  o(g(n))
– f(n) relative to g(n)equals some value less than infinity as n
approaches infinity:
lim [f(n) / g(n)] < 
n
W -notation (Big-omega):
– f(n)  W(g(n))  f(n)  Q(g(n))and f(n)  w(g(n))
– f(n) relative to g(n)equals some value greater than 0 as n
approaches infinity:
0 < lim [f(n) / g(n)]
n
CS 321 - Data Structures 14
Examples
Use limit definitions to prove:
– 10n - 3n  O(n2)
– 3n4  W(n3)
– n2/2 - 3n  Q(n2)
– 22n Q(2n)
CS 321 - Data Structures 15
Examples
Use limit definitions to prove:
– 10n - 3n  O(n2) – Yes!
lim [ 10n - 3n / n2 ] = 0
n
– 3n4  W(n3) – Yes!
lim [ 3n4 / n3 ] = 
n
– n2/2 - 3n  Q(n2) – Yes!
lim [ n2/2 - 3n / n2 ] = 1/2
n
– 22n Q(2n) – No!
lim [ 22n / 2n ] = 
n
CS 321 - Data Structures 16
Why Do We Care?
CS 321 - Data Structures 17
T(n)
n n n log n n2
n3
n4
n10
2n
10 .01ms .03ms .1ms 1ms 10ms 10s 1ms
20 .02ms .09ms .4ms 8ms 160ms 2.84h 1ms
30 .03ms .15ms .9ms 27ms 810ms 6.83d 1s
40 .04ms .21ms 1.6ms 64ms 2.56ms 121d 18m
50 .05ms .28ms 2.5ms 125ms 6.25ms 3.1y 13d
100 .1ms .66ms 10ms 1ms 100ms 3171y 4´1013
y
103
1ms 9.96ms 1ms 1s 16.67m 3.17´1013
y 32´10283
y
104
10ms 130ms 100ms 16.67m 115.7d 3.17´1023
y
105
100ms 1.66ms 10s 11.57d 3171y 3.17´1033
y
106
1ms 19.92ms 16.67m 31.71y 3.17´107
y 3.17´1043
y
Complexity and Tractability
Assuming the microprocessor performs 1 billion ops/s.
CS 321 - Data Structures 18
CS 321 - Data Structures 19

More Related Content

PPT
Asymtotic Appoach.ppt
PPT
02-asymp.ppt
PPTX
Asymptotic notations for desing analysis of algorithm.pptx
PDF
DAA_LECT_2.pdf
PPT
ASYMTOTIC NOTATION ON DATA STRUCTURE AND ALGORITHM
PPT
02-asymp.ppt YJTYJTYFHYTYHFHTFTHFHTFTHFTHTHFT
PPT
DSA Asymptotic Notations and Functions.ppt
PPT
02-asymp.ppt01_Intro.ppt algorithm for preperation stu used
Asymtotic Appoach.ppt
02-asymp.ppt
Asymptotic notations for desing analysis of algorithm.pptx
DAA_LECT_2.pdf
ASYMTOTIC NOTATION ON DATA STRUCTURE AND ALGORITHM
02-asymp.ppt YJTYJTYFHYTYHFHTFTHFHTFTHFTHTHFT
DSA Asymptotic Notations and Functions.ppt
02-asymp.ppt01_Intro.ppt algorithm for preperation stu used

Similar to 2-AnalysisOfAlgs.ppt (20)

PDF
asymptoticnotations-111102093214-phpapp01 (1).pdf
PPT
Design and analysis of algorithm ppt ppt
PPT
02 asymp
PPTX
Asymptotic notation
PPTX
Asymptotic ssssssssssssssssssssssssssssss.pptx
PPTX
Asymptotic notations
PPTX
Binary search design and ana algorithm.pptx
PDF
02 CS316_algorithms_Asymptotic_Notations(2).pdf
PPTX
Asymptotic Notation
PDF
Lecture3(b).pdf
PDF
Lecture 3(a) Asymptotic-analysis.pdf
PPTX
Lecture 2 data structures and algorithms
PDF
Introduction to analysis algorithm in computer Science 2
PDF
asymptomatic notations and analysis in computer science
PPTX
02 asymptotic notations
PPTX
Asymptotic notation
PPT
Asymptotic Notation and Complexity
PPTX
1.algorithms
PDF
2. Asymptotic Notation- Analysis of Algorithms.pdf
PPT
DESIGN AND ANALYSIS OF ALGORITHMS
asymptoticnotations-111102093214-phpapp01 (1).pdf
Design and analysis of algorithm ppt ppt
02 asymp
Asymptotic notation
Asymptotic ssssssssssssssssssssssssssssss.pptx
Asymptotic notations
Binary search design and ana algorithm.pptx
02 CS316_algorithms_Asymptotic_Notations(2).pdf
Asymptotic Notation
Lecture3(b).pdf
Lecture 3(a) Asymptotic-analysis.pdf
Lecture 2 data structures and algorithms
Introduction to analysis algorithm in computer Science 2
asymptomatic notations and analysis in computer science
02 asymptotic notations
Asymptotic notation
Asymptotic Notation and Complexity
1.algorithms
2. Asymptotic Notation- Analysis of Algorithms.pdf
DESIGN AND ANALYSIS OF ALGORITHMS
Ad

Recently uploaded (20)

PPTX
Institutional Correction lecture only . . .
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Pharma ospi slides which help in ospi learning
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Business Ethics Teaching Materials for college
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Cell Structure & Organelles in detailed.
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
Institutional Correction lecture only . . .
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
01-Introduction-to-Information-Management.pdf
Microbial diseases, their pathogenesis and prophylaxis
Supply Chain Operations Speaking Notes -ICLT Program
PPH.pptx obstetrics and gynecology in nursing
VCE English Exam - Section C Student Revision Booklet
Pharma ospi slides which help in ospi learning
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
human mycosis Human fungal infections are called human mycosis..pptx
Business Ethics Teaching Materials for college
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
O7-L3 Supply Chain Operations - ICLT Program
Cell Structure & Organelles in detailed.
Anesthesia in Laparoscopic Surgery in India
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Week 4 Term 3 Study Techniques revisited.pptx
Ad

2-AnalysisOfAlgs.ppt

  • 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. Describes behavior of function in the limit. Written using Asymptotic Notation. CS 321 - Data Structures 2
  • 3. 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. Defines a set of functions; in practice used to compare growth rate of two functions. The notations describe the relationship between the defining function and a defined set of functions. CS 321 - Data Structures 3
  • 4. 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)) CS 321 - Data Structures 4
  • 5. 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: CS 321 - Data Structures 5
  • 6. 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). CS 321 - Data Structures 6
  • 7. Relationship Between Q, O, W CS 321 - Data Structures 7
  • 8. Relationship Between Q, W, O 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)). CS 321 - Data Structures 8
  • 9. o-notation g(n) is an upper bound for f(n)that is not asymptotically tight. 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: Intuitively: Set of all functions whose rate of growth is lower than that of g(n). CS 321 - Data Structures 9
  • 10. w(g(n)) = {f(n):  c > 0,  n0 > 0 such that  n  n0, we have 0  cg(n) < f(n)}. w -notation g(n) is a lower bound for f(n) that is not asymptotically tight. For a given function g(n), the set little-omega: Intuitively: Set of all functions whose rate of growth is higher than that of g(n). CS 321 - Data Structures 10
  • 11. 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 CS 321 - Data Structures 11
  • 12. Limit Definitions of Asymptotic Notations o-notation (little-o): – f(n) becomes insignificant relative to g(n) as n approaches infinity: lim [f(n) / g(n)] = 0 n w -notation (little-omega): – f(n) becomes arbitrarily large relative to g(n) as n approaches infinity: lim [f(n) / g(n)] =  n CS 321 - Data Structures 12
  • 13. Limit Definitions of Asymptotic Notations Q-notation (Big-theta): – f(n) relative to g(n)equals a constant, c, which is greater than 0 and less than infinity as n approaches infinity: 0 < lim [f(n) / g(n)] <  n CS 321 - Data Structures 13
  • 14. Limit Definitions of Asymptotic Notations O-notation (Big-o): – f(n)  O(g(n))  f(n)  Q(g(n))and f(n)  o(g(n)) – f(n) relative to g(n)equals some value less than infinity as n approaches infinity: lim [f(n) / g(n)] <  n W -notation (Big-omega): – f(n)  W(g(n))  f(n)  Q(g(n))and f(n)  w(g(n)) – f(n) relative to g(n)equals some value greater than 0 as n approaches infinity: 0 < lim [f(n) / g(n)] n CS 321 - Data Structures 14
  • 15. Examples Use limit definitions to prove: – 10n - 3n  O(n2) – 3n4  W(n3) – n2/2 - 3n  Q(n2) – 22n Q(2n) CS 321 - Data Structures 15
  • 16. Examples Use limit definitions to prove: – 10n - 3n  O(n2) – Yes! lim [ 10n - 3n / n2 ] = 0 n – 3n4  W(n3) – Yes! lim [ 3n4 / n3 ] =  n – n2/2 - 3n  Q(n2) – Yes! lim [ n2/2 - 3n / n2 ] = 1/2 n – 22n Q(2n) – No! lim [ 22n / 2n ] =  n CS 321 - Data Structures 16
  • 17. Why Do We Care? CS 321 - Data Structures 17
  • 18. T(n) n n n log n n2 n3 n4 n10 2n 10 .01ms .03ms .1ms 1ms 10ms 10s 1ms 20 .02ms .09ms .4ms 8ms 160ms 2.84h 1ms 30 .03ms .15ms .9ms 27ms 810ms 6.83d 1s 40 .04ms .21ms 1.6ms 64ms 2.56ms 121d 18m 50 .05ms .28ms 2.5ms 125ms 6.25ms 3.1y 13d 100 .1ms .66ms 10ms 1ms 100ms 3171y 4´1013 y 103 1ms 9.96ms 1ms 1s 16.67m 3.17´1013 y 32´10283 y 104 10ms 130ms 100ms 16.67m 115.7d 3.17´1023 y 105 100ms 1.66ms 10s 11.57d 3171y 3.17´1033 y 106 1ms 19.92ms 16.67m 31.71y 3.17´107 y 3.17´1043 y Complexity and Tractability Assuming the microprocessor performs 1 billion ops/s. CS 321 - Data Structures 18
  • 19. CS 321 - Data Structures 19