SlideShare a Scribd company logo
1 of 29
Design and Analysis of Algorithms Chapter 2.2
1
Asymptotic Notations*
Dr. Ying Lu
ylu@cse.unl.edu
August 30, 2012
http://www.cse.unl.edu/~ylu/raik283
RAIK 283: Data Structures & Algorithms
*slides refrred to
http://www.aw-bc.com/info/levitin
Design and Analysis of Algorithms Chapter 2.2
2
Review: algorithm efficiency indicator
order of growth
of
an algorithm’s basic operation count
the algorithm’s time efficiency
Design and Analysis of Algorithms Chapter 2.2
3
Asymptotic growth rate
 A way of comparing functions that ignores constant factors
and small input sizes
 O(g(n)): class of functions t(n) that grow no faster than g(n)
 Θ (g(n)): class of functions t(n) that grow at same rate as g(n)
 Ω(g(n)): class of functions t(n) that grow at least as fast as g(n)
Design and Analysis of Algorithms Chapter 2.2
4
Big-oh
c > 0, n0  0 , n  n0, t(n)  cg(n)
t(n)  O(g(n))
Design and Analysis of Algorithms Chapter 2.2
5
Small-oh
c > 0, n0  0 , n  n0, t(n) < cg(n)
t(n)  o(g(n))
Design and Analysis of Algorithms Chapter 2.2
6
Big-omega
t(n)  (g(n))
Design and Analysis of Algorithms Chapter 2.2
7
Big-omega
c > 0, n0  0 , n  n0, t(n)  cg(n)
t(n)  (g(n))
Design and Analysis of Algorithms Chapter 2.2
8
Small-omega
c > 0, n0  0 , n  n0, t(n) > cg(n)
t(n)  (g(n))
Design and Analysis of Algorithms Chapter 2.2
9
Big-theta
t(n)  (g(n))
c1>c2>0, n00, n  n0, c2g(n)  t(n)  c1g(n)
Design and Analysis of Algorithms Chapter 2.2
10
Big theta
The reverse statement of
t(n)  (g(n))
c1>c2>0, n00, n  n0, c2g(n)  t(n)  c1g(n)
Design and Analysis of Algorithms Chapter 2.2
11
Big theta
t(n)  (g(n))
c1>c2>0, n00, n  n0, t(n) < c2g(n) or t(n) > c1g(n)
Design and Analysis of Algorithms Chapter 2.2
12
Establishing rate of growth: Method 1 – using definition
 t(n) is O(g(n)) if order of growth of t(n) ≤ order of growth
of g(n) (within constant multiple)
 There exist positive constant c and non-negative integer n0
such that
t(n) ≤ c g(n) for every n ≥ n0
Examples:
 10n  O(2n2)
 5n+20  O(10n)
Design and Analysis of Algorithms Chapter 2.2
13
A B O Ω Θ
1 ln2n n e Yes No No
2 nk cn Yes No No
3 nsinn No No No
4 2n 2n/2 No Yes No
5 nlgc clgn Yes Yes Yes
6 lg(n!) lg(nn) Yes Yes Yes
n
2n  (2n/2) 2n  (2n/2)
Establishing rate of growth: Method 1 – using definition
Examples:
Design and Analysis of Algorithms Chapter 2.2
14
A B O Ω Θ
1 ln2n n e Yes No No
2 nk cn Yes No No
3 nsinn No No No
4 2n 2n/2 No Yes No
5 nlgc clgn Yes Yes Yes
6 lg(n!) lg(nn) Yes Yes Yes
n
 O(nsinn)  (nsinn)
n n
Establishing rate of growth: Method 1 – using definition
Examples:
Design and Analysis of Algorithms Chapter 2.2
15
Establishing rate of growth: Method 2 – using limits
limn→∞ t(n)/g(n)
0 order of growth of t(n) < order of growth of g(n)
t(n)  o(g(n)), t(n)  O(g(n))
c>0 order of growth of t(n) = order of growth of g(n)
t(n)  (g(n)), t(n)  O(g(n)), t(n)  (g(n))
∞ order of growth of t(n) > order of growth of g(n)
t(n)  (g(n)), t(n)  (g(n))
=
Design and Analysis of Algorithms Chapter 2.2
16
Establishing rate of growth: Method 2 – using limits
Examples:
• logb n vs. logc n
logbn = logbc logcn
limn→∞( logbn / logcn) = limn→∞ (logbc) = logbc
logbn (logcn)
Design and Analysis of Algorithms Chapter 2.2
17
Exercises: establishing rate of growth – using limits
 ln2n vs. lnn2
 2n vs. 2n/2
 2n-1 vs. 2n
 log2n vs. n
Design and Analysis of Algorithms Chapter 2.2
18
L’Hôpital’s rule
If
 limn→∞ t(n) = limn→∞ g(n) = ∞
 The derivatives f´, g´ exist,
Then
t(n)
g(n)
lim
n→∞
=
t ´(n)
g ´(n)
lim
n→∞
• Example: log2n vs. n
Design and Analysis of Algorithms Chapter 2.2
19
A B O Ω Θ
1 ln2n n e Yes No No
2 nk cn Yes No No
3 nsinn No No No
4 2n 2n/2 No Yes No
5 nlgc clgn Yes Yes Yes
6 lg(n!) lg(nn) Yes Yes Yes
n
Establishing rate of growth
Examples:
Design and Analysis of Algorithms Chapter 2.2
20
Stirling’s formula
n
e
n
n
n )
(
2
! 

Design and Analysis of Algorithms Chapter 2.2
21
n! v.s. nn
lg(n!) v.s. lg(nn)
Examples using stirling’s formula
  O
Design and Analysis of Algorithms Chapter 2.2
22
n!  o(nn)
lg(n!) v.s. lg(nn)
??? lg(n!)  o(lg(nn))
Examples using stirling’s formula
  O
Design and Analysis of Algorithms Chapter 2.2
23
n!  o(nn)
lg(n!) v.s. lg(nn)
lg(n!)  (lg(nn))
Examples using stirling’s formula
  O
Design and Analysis of Algorithms Chapter 2.2
24
Special attention
 n!  o(nn)
However,
lg(n!)  o(lg(nn)) lg(n!)  (lg(nn))
 sinn   (1/2) sinn  O(1/2) sinn  (1/2)
However,
n1/2  (nsinn) n1/2  O(nsinn) n1/2  (nsinn)
Design and Analysis of Algorithms Chapter 2.2
25
Asymptotic notation 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))
 If t1(n)  O(g1(n)) and t2(n)  O(g2(n)), then
t1(n) + t2(n) 
Design and Analysis of Algorithms Chapter 2.2
26
Asymptotic notation 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))
 If t1(n)  O(g1(n)) and t2(n)  O(g2(n)), then
t1(n) + t2(n)  O(max{g1(n), g2(n)})
In-Class Exercises
 Exercises 2.2: Problem 1, 2, 3 & 12
 Problem 1: Use the most appropriate notation among O, ,
and  to indicate the time efficiency class of sequential
search:
• a. in the worst case
• b. in the best case
• c. in the average case ( Hint: C(n) = p*(n+1)/2 + (1-p)*n )
 Problem 2: Use the informal definitions of O, , and  to
determine whether the following assertions are true or
false.
• a. n(n+1)/2  O(n3) b. n(n+1)/2  O(n2)
• c. n(n+1)/2  (n3) d. n(n+1)/2  (n)
Design and Analysis of Algorithms Chapter 2.2
27
Announcement
 40-minute quiz next Tuesday
• problems based on materials covered in Chapter 2.2 (Asymptotic
Notations and Basic Efficiency Classes)
Design and Analysis of Algorithms Chapter 2.2
28
In-Class Exercises
 Establish the asymptotic rate of growth (O, , and ) of
the following pair of functions. Prove your assertions.
• a. 2n vs. 3n b. ln(n+1) vs. ln(n)
 Problem 3: For each of the following functions, indicate the
class (g(n)) the function belongs to. (Use the simplest g(n)
possible in your answers.) Prove your assertions.
• a. (n2 + 1)10 b.
• c. 2nlg(n+2)2 + (n+2)2lg(n/2)
• d. 2n+1 + 3n-1 e. log2n
Design and Analysis of Algorithms Chapter 2.2
29
3
7
10 2

 n
n

More Related Content

Similar to AsymptoticNotations.ppt

lecture 1
lecture 1lecture 1
lecture 1
sajinsc
 
Container and algorithms(C++)
Container and algorithms(C++)Container and algorithms(C++)
Container and algorithms(C++)
JerryHe
 
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
DebiPrasadSen
 
Algorithm chapter 2
Algorithm chapter 2Algorithm chapter 2
Algorithm chapter 2
chidabdu
 

Similar to AsymptoticNotations.ppt (20)

AsymptoticAnalysis.ppt
AsymptoticAnalysis.pptAsymptoticAnalysis.ppt
AsymptoticAnalysis.ppt
 
Algorithm.ppt
Algorithm.pptAlgorithm.ppt
Algorithm.ppt
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
 
lecture 1
lecture 1lecture 1
lecture 1
 
1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
 
Asymptotic analysis
Asymptotic analysisAsymptotic analysis
Asymptotic analysis
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
 
Container and algorithms(C++)
Container and algorithms(C++)Container and algorithms(C++)
Container and algorithms(C++)
 
CS-102 DS-class_01_02 Lectures Data .pdf
CS-102 DS-class_01_02 Lectures Data .pdfCS-102 DS-class_01_02 Lectures Data .pdf
CS-102 DS-class_01_02 Lectures Data .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
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
 
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
 
CMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of FunctionsCMSC 56 | Lecture 8: Growth of Functions
CMSC 56 | Lecture 8: Growth of Functions
 
2 funda.ppt
2 funda.ppt2 funda.ppt
2 funda.ppt
 
AlgorithmAnalysis2.ppt
AlgorithmAnalysis2.pptAlgorithmAnalysis2.ppt
AlgorithmAnalysis2.ppt
 
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
Algorithms required for data structures(basics like Arrays, Stacks ,Linked Li...
 
Basics & asymptotic notations
Basics & asymptotic notationsBasics & asymptotic notations
Basics & asymptotic notations
 
Analysis of Algorithum
Analysis of AlgorithumAnalysis of Algorithum
Analysis of Algorithum
 
Algorithm chapter 2
Algorithm chapter 2Algorithm chapter 2
Algorithm chapter 2
 
introduction to algorithm for beginneer1
introduction to algorithm for beginneer1introduction to algorithm for beginneer1
introduction to algorithm for beginneer1
 

More from Senthil Vit (14)

Switching Problems.pdf
Switching Problems.pdfSwitching Problems.pdf
Switching Problems.pdf
 
Big Oh.ppt
Big Oh.pptBig Oh.ppt
Big Oh.ppt
 
snort.ppt
snort.pptsnort.ppt
snort.ppt
 
First Best and Worst Fit.pptx
First Best and Worst Fit.pptxFirst Best and Worst Fit.pptx
First Best and Worst Fit.pptx
 
File Implementation Problem.pptx
File Implementation Problem.pptxFile Implementation Problem.pptx
File Implementation Problem.pptx
 
Design Issues of an OS.ppt
Design Issues of an OS.pptDesign Issues of an OS.ppt
Design Issues of an OS.ppt
 
Operating Systems – Structuring Methods.pptx
Operating Systems – Structuring Methods.pptxOperating Systems – Structuring Methods.pptx
Operating Systems – Structuring Methods.pptx
 
deadlock.ppt
deadlock.pptdeadlock.ppt
deadlock.ppt
 
Virtualization.pptx
Virtualization.pptxVirtualization.pptx
Virtualization.pptx
 
Traffic-Monitoring.ppt
Traffic-Monitoring.pptTraffic-Monitoring.ppt
Traffic-Monitoring.ppt
 
Lect_2.pptx
Lect_2.pptxLect_2.pptx
Lect_2.pptx
 
6. Deadlock.ppt
6. Deadlock.ppt6. Deadlock.ppt
6. Deadlock.ppt
 
os4-2_cop.ppt
os4-2_cop.pptos4-2_cop.ppt
os4-2_cop.ppt
 
ALPHA_BETA_EXAMPLE_PROB
ALPHA_BETA_EXAMPLE_PROBALPHA_BETA_EXAMPLE_PROB
ALPHA_BETA_EXAMPLE_PROB
 

Recently uploaded

Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
Kira Dess
 
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
c3384a92eb32
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
rahulmanepalli02
 
01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...
01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...
01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...
AshwaniAnuragi1
 

Recently uploaded (20)

Basics of Relay for Engineering Students
Basics of Relay for Engineering StudentsBasics of Relay for Engineering Students
Basics of Relay for Engineering Students
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
 
Circuit Breakers for Engineering Students
Circuit Breakers for Engineering StudentsCircuit Breakers for Engineering Students
Circuit Breakers for Engineering Students
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
 
Presentation on Slab, Beam, Column, and Foundation/Footing
Presentation on Slab,  Beam, Column, and Foundation/FootingPresentation on Slab,  Beam, Column, and Foundation/Footing
Presentation on Slab, Beam, Column, and Foundation/Footing
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
 
Filters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility ApplicationsFilters for Electromagnetic Compatibility Applications
Filters for Electromagnetic Compatibility Applications
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
一比一原版(Griffith毕业证书)格里菲斯大学毕业证成绩单学位证书
 
DBMS-Report on Student management system.pptx
DBMS-Report on Student management system.pptxDBMS-Report on Student management system.pptx
DBMS-Report on Student management system.pptx
 
Raashid final report on Embedded Systems
Raashid final report on Embedded SystemsRaashid final report on Embedded Systems
Raashid final report on Embedded Systems
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
 
Databricks Generative AI Fundamentals .pdf
Databricks Generative AI Fundamentals  .pdfDatabricks Generative AI Fundamentals  .pdf
Databricks Generative AI Fundamentals .pdf
 
Path loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata ModelPath loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata Model
 
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and ToolsMaximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
 
01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...
01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...
01-vogelsanger-stanag-4178-ed-2-the-new-nato-standard-for-nitrocellulose-test...
 
Databricks Generative AI FoundationCertified.pdf
Databricks Generative AI FoundationCertified.pdfDatabricks Generative AI FoundationCertified.pdf
Databricks Generative AI FoundationCertified.pdf
 

AsymptoticNotations.ppt

  • 1. Design and Analysis of Algorithms Chapter 2.2 1 Asymptotic Notations* Dr. Ying Lu ylu@cse.unl.edu August 30, 2012 http://www.cse.unl.edu/~ylu/raik283 RAIK 283: Data Structures & Algorithms *slides refrred to http://www.aw-bc.com/info/levitin
  • 2. Design and Analysis of Algorithms Chapter 2.2 2 Review: algorithm efficiency indicator order of growth of an algorithm’s basic operation count the algorithm’s time efficiency
  • 3. Design and Analysis of Algorithms Chapter 2.2 3 Asymptotic growth rate  A way of comparing functions that ignores constant factors and small input sizes  O(g(n)): class of functions t(n) that grow no faster than g(n)  Θ (g(n)): class of functions t(n) that grow at same rate as g(n)  Ω(g(n)): class of functions t(n) that grow at least as fast as g(n)
  • 4. Design and Analysis of Algorithms Chapter 2.2 4 Big-oh c > 0, n0  0 , n  n0, t(n)  cg(n) t(n)  O(g(n))
  • 5. Design and Analysis of Algorithms Chapter 2.2 5 Small-oh c > 0, n0  0 , n  n0, t(n) < cg(n) t(n)  o(g(n))
  • 6. Design and Analysis of Algorithms Chapter 2.2 6 Big-omega t(n)  (g(n))
  • 7. Design and Analysis of Algorithms Chapter 2.2 7 Big-omega c > 0, n0  0 , n  n0, t(n)  cg(n) t(n)  (g(n))
  • 8. Design and Analysis of Algorithms Chapter 2.2 8 Small-omega c > 0, n0  0 , n  n0, t(n) > cg(n) t(n)  (g(n))
  • 9. Design and Analysis of Algorithms Chapter 2.2 9 Big-theta t(n)  (g(n)) c1>c2>0, n00, n  n0, c2g(n)  t(n)  c1g(n)
  • 10. Design and Analysis of Algorithms Chapter 2.2 10 Big theta The reverse statement of t(n)  (g(n)) c1>c2>0, n00, n  n0, c2g(n)  t(n)  c1g(n)
  • 11. Design and Analysis of Algorithms Chapter 2.2 11 Big theta t(n)  (g(n)) c1>c2>0, n00, n  n0, t(n) < c2g(n) or t(n) > c1g(n)
  • 12. Design and Analysis of Algorithms Chapter 2.2 12 Establishing rate of growth: Method 1 – using definition  t(n) is O(g(n)) if order of growth of t(n) ≤ order of growth of g(n) (within constant multiple)  There exist positive constant c and non-negative integer n0 such that t(n) ≤ c g(n) for every n ≥ n0 Examples:  10n  O(2n2)  5n+20  O(10n)
  • 13. Design and Analysis of Algorithms Chapter 2.2 13 A B O Ω Θ 1 ln2n n e Yes No No 2 nk cn Yes No No 3 nsinn No No No 4 2n 2n/2 No Yes No 5 nlgc clgn Yes Yes Yes 6 lg(n!) lg(nn) Yes Yes Yes n 2n  (2n/2) 2n  (2n/2) Establishing rate of growth: Method 1 – using definition Examples:
  • 14. Design and Analysis of Algorithms Chapter 2.2 14 A B O Ω Θ 1 ln2n n e Yes No No 2 nk cn Yes No No 3 nsinn No No No 4 2n 2n/2 No Yes No 5 nlgc clgn Yes Yes Yes 6 lg(n!) lg(nn) Yes Yes Yes n  O(nsinn)  (nsinn) n n Establishing rate of growth: Method 1 – using definition Examples:
  • 15. Design and Analysis of Algorithms Chapter 2.2 15 Establishing rate of growth: Method 2 – using limits limn→∞ t(n)/g(n) 0 order of growth of t(n) < order of growth of g(n) t(n)  o(g(n)), t(n)  O(g(n)) c>0 order of growth of t(n) = order of growth of g(n) t(n)  (g(n)), t(n)  O(g(n)), t(n)  (g(n)) ∞ order of growth of t(n) > order of growth of g(n) t(n)  (g(n)), t(n)  (g(n)) =
  • 16. Design and Analysis of Algorithms Chapter 2.2 16 Establishing rate of growth: Method 2 – using limits Examples: • logb n vs. logc n logbn = logbc logcn limn→∞( logbn / logcn) = limn→∞ (logbc) = logbc logbn (logcn)
  • 17. Design and Analysis of Algorithms Chapter 2.2 17 Exercises: establishing rate of growth – using limits  ln2n vs. lnn2  2n vs. 2n/2  2n-1 vs. 2n  log2n vs. n
  • 18. Design and Analysis of Algorithms Chapter 2.2 18 L’Hôpital’s rule If  limn→∞ t(n) = limn→∞ g(n) = ∞  The derivatives f´, g´ exist, Then t(n) g(n) lim n→∞ = t ´(n) g ´(n) lim n→∞ • Example: log2n vs. n
  • 19. Design and Analysis of Algorithms Chapter 2.2 19 A B O Ω Θ 1 ln2n n e Yes No No 2 nk cn Yes No No 3 nsinn No No No 4 2n 2n/2 No Yes No 5 nlgc clgn Yes Yes Yes 6 lg(n!) lg(nn) Yes Yes Yes n Establishing rate of growth Examples:
  • 20. Design and Analysis of Algorithms Chapter 2.2 20 Stirling’s formula n e n n n ) ( 2 !  
  • 21. Design and Analysis of Algorithms Chapter 2.2 21 n! v.s. nn lg(n!) v.s. lg(nn) Examples using stirling’s formula   O
  • 22. Design and Analysis of Algorithms Chapter 2.2 22 n!  o(nn) lg(n!) v.s. lg(nn) ??? lg(n!)  o(lg(nn)) Examples using stirling’s formula   O
  • 23. Design and Analysis of Algorithms Chapter 2.2 23 n!  o(nn) lg(n!) v.s. lg(nn) lg(n!)  (lg(nn)) Examples using stirling’s formula   O
  • 24. Design and Analysis of Algorithms Chapter 2.2 24 Special attention  n!  o(nn) However, lg(n!)  o(lg(nn)) lg(n!)  (lg(nn))  sinn   (1/2) sinn  O(1/2) sinn  (1/2) However, n1/2  (nsinn) n1/2  O(nsinn) n1/2  (nsinn)
  • 25. Design and Analysis of Algorithms Chapter 2.2 25 Asymptotic notation 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))  If t1(n)  O(g1(n)) and t2(n)  O(g2(n)), then t1(n) + t2(n) 
  • 26. Design and Analysis of Algorithms Chapter 2.2 26 Asymptotic notation 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))  If t1(n)  O(g1(n)) and t2(n)  O(g2(n)), then t1(n) + t2(n)  O(max{g1(n), g2(n)})
  • 27. In-Class Exercises  Exercises 2.2: Problem 1, 2, 3 & 12  Problem 1: Use the most appropriate notation among O, , and  to indicate the time efficiency class of sequential search: • a. in the worst case • b. in the best case • c. in the average case ( Hint: C(n) = p*(n+1)/2 + (1-p)*n )  Problem 2: Use the informal definitions of O, , and  to determine whether the following assertions are true or false. • a. n(n+1)/2  O(n3) b. n(n+1)/2  O(n2) • c. n(n+1)/2  (n3) d. n(n+1)/2  (n) Design and Analysis of Algorithms Chapter 2.2 27
  • 28. Announcement  40-minute quiz next Tuesday • problems based on materials covered in Chapter 2.2 (Asymptotic Notations and Basic Efficiency Classes) Design and Analysis of Algorithms Chapter 2.2 28
  • 29. In-Class Exercises  Establish the asymptotic rate of growth (O, , and ) of the following pair of functions. Prove your assertions. • a. 2n vs. 3n b. ln(n+1) vs. ln(n)  Problem 3: For each of the following functions, indicate the class (g(n)) the function belongs to. (Use the simplest g(n) possible in your answers.) Prove your assertions. • a. (n2 + 1)10 b. • c. 2nlg(n+2)2 + (n+2)2lg(n/2) • d. 2n+1 + 3n-1 e. log2n Design and Analysis of Algorithms Chapter 2.2 29 3 7 10 2   n n