SlideShare a Scribd company logo
CS316: ALGORI
THM S
Lecture 2
ANALYSI
SOFALGORI
THM S
1
Prepared by: Assoc. Prof. Ensaf Hussein
Presented by:
Assoc. Prof. Wessam El-Behaidy
Dr. Mohammed El-Said
ASYMPTOTIC NOTATIONSAND BASIC
EFFICIENCYCLASSES
3
BOUNDS(ASYMPTOTIC NOTATIONS)
Critical factor for problem size n:
 I
S NOT the exact number of basic operations
executed for given n
 I
S how number of basic operations grow s as n
increases
Consequently:
 Focus on how performance grows as n  

 Ignore constant factors
Call this:Asymptotic Order of Grow th
Bounds describe the limiting behavior of algorithm
complexity at large (n). They are:
Worst Case:Upper Bound (Big O complexity)
Best Case:Lower Bound (Big  complexity)
Exact (Big  complexity)
Approach:classify functions (i.e. of algorithms
performance) based on their growth rates and divide
into sets
4
BOUNDS (ASYMPTOTI
C NOTATI
ONS)
W
Q
O
O-NOTATION: DEFINITION
Worst Case Upper Bound (Big O)
class of functions (algorithms) f(n) that grow
no faster than g(n)
order of growth of f(n) ≤ order of growth of
g(n) (within constant multiple).
f(n) of the algorithm
g(n) is one of growth functions
O-NOTATION :DEFINITION 1
O-NOTATION :
x 
O (x2)? Yes, c = 1, n0=1 works fine.
10x  O (x)? Yes, c = 11, n0=1 works fine.
x2  O (x)? No, no matter what c and n0
we pick, cx2 > x for big enough x
f (n) 
O (g (n)) means:there are positive
constants c and n0 such that f(n)  c g(n) for all
values n  n0.
Then:
O-NOTATION :
O(n3)
O(n2)
f(n) = n2.5
f(n) = 12n2 + n
f(n) = n3.1 – n2
Hence,only the fastest-grow ing term in f matters
O-NOTATI
ON :EXAMPLES
Example : Using basic definition, we show that
3n2 + 10n ϵ O(n2)
Consider, 10 ≤ n for n ≥ 10 ( obvious !
)
10n ≤ n2 for n ≥ 10 ( Multiplying both sides with n )
3n2+10n ≤ 3n2 + n2 for n ≥ 10 ( Adding 3n2 to both sides )
=4n2 (Simplifying )
3n2 + 10 n ≤ c.n2 for n ≥ n0 where c =4 and n0= 10 (Solution)
Therefore, it follows from the basic definition that
3n2 +10n = O(n2)
The choice of constant c is not unique. However, for each
different c there is a corresponding value of n0 which satisfies
the basic relation .This behavior is illustrated by the next
example
Example : In the preceding example it was shown that
3n2 + 10n ≤ c.n2 for c=4, n0=10.
We now show that the relation holds true for a different value of
c and corresponding n0.
Consider n ≤ n2 for n ≥ 1 ( Obvious)
10n ≤ 10n2 for n≥ 1 (Multiplying both sides with 10 )
3n2 +10 n ≤ 3n2 + 10n2 for n≥ 1 ( Adding 3n2 on both
sides)
3n2 +10n ≤ 13n2 for n ≥ 1 ( Simplifying )
Or,
3n2 +10n ≤ c.n2, for n ≥ n0 where c=13, n0=1 ( Solution )
Therefore, by basic definition,
3n2 + 10n = O(n2)
O-NOTATION EXAMPLE
COMPARISON OF GROWTH RATES
The results of analysis in the preceding examples
are plotted in the next diagram.
It can be seen that the function cg(n) =4n2 ( c= 4)
overshoots the function f(n)= 3n2 + 10n for n0=10.
Also, the function cg(n) =13n2 ( c =13 ) grows
faster than f(n) = 3n2 + 10n for n0=1
Growth of functions 13n2 and 4n2 versus the function 3n2 + 10 n
Tight upper
bound
Ω-NOTATION: DEFINITION
Best Case:Low er Bound (Big  
class of functions f(n) that grow at least as
fast as g(n)
If order of growth of f(n) ≥ order of growth
of g(n) (within constant multiple).
f(n) ≥ c.g(n) for all n ≥ n0
Ω-NOTATION: DEFINITION
Let f and g be functions from the set of integers or
the set of real numbers to the set of real numbers. We
say that f(x) is  (g(x)) or f(x) =  (g(x))
(read as: “
f(x) is big-omega of g(x)”
) if there are
constants C and n0 such that
c.g(n) ≤ f(n) for all n ≥ n0
lim
→ ∞
( )
( )
= c ,
where c is a positive constant such that 0 < c ≤ ∞
Ω-NOTATION
BASIC METHOD
Example: Using basic definition, we show that
n3 ϵ Ω(n2).
For, n3 ≥ n2 for n ≥ 0
i.e. we can select c=1 and n0= 0
02 CS316_algorithms_Asymptotic_Notations(2).pdf
Θ-NOTATION: DEFINITION
Exact (Big  complexity)
Class of functions f(n) that grow at same rate
as g(n)
Order of growth of f(n) = order of growth
of g(n) (within constant multiples).
c2.g(n) ≤ f(n) ≤ c1.g(n)
for all n ≥ n0
Θ-NOTATION: DEFINITION
Let f and g be functions from the set of integers or the set
of real numbers to the set of real numbers. We say that
f(x) = (g(x)) or f(x) is in order (g(x))
if f(x) = O(g(x)) and f(x) =  (g(x)).
such that for some positive constants c1 , c2 and positive
integer n0 ,
0 < c2.g(n) ≤ f(n) ≤ c1.g(n) for all n ≥ n0
lim
→ ∞
( )
( )
= c ,
where c is a positive constant such that 0 < c < ∞
Example: We show that ½ n (n-1) ϵ θ(n2).
We need to prove that
c2 g(n) ≤ F(n) ≤ c1 g(n) for all n ≥ no
first, consider the upper bound,
F(n) ≤ c1 g(n)
½ n2 – ½ n ≤ ½ n2 for all n ≥ 0.
Second, consider the lower bound,
F(n) ≥ c2 g(n)
½ n2 – ½ n ≥ ½ n2 – ½ n ½ n for all n ≥ 2.
= ¼ n2.
Hence we can select c2 = ¼ , c1= ½ , and n0 = 2.
½ n(n-1) = ½ n2 – ½ n
COMPARISON OF GROWTH RATES
21
BOUNDS(ASYMPTOTIC NOTATIONS)
W
Q
O
f(n) ≤ c × g(n)
for all n ≥ n0
n
n0
c × g(n)
f(n)
f(n) є O(g(n))
f(n) ≥ c × g(n)
for all n ≥ n0
n0
f(n)
c × g(n)
n
f(n) є Ω(g(n))
c2×g(n) ≤ f(n) ≤ c1×g(n)
for all n ≥ n0
n
f(n) є Θ(g(n))
c1 × g(n)
c2 × g(n)
f(n)
n0
Theorem :
(
1) Suppose f1(
x
)= O(
g1(
x
)
)and f2(
x
)= O(
g2(
x
)
)then
(
f1+f2)
(
x
) = O (
max
(
g1(
x
)
,g2(
x
)
)
Example 1:Theorem 1
If our problem contains sorting inputs, then search within.
Consider sorting algorithm= O(n2) comparisons and then binary
search = O(log2n) comparisons, then:
efficiency is O(max{n2, log2n}) = O(n2)
Example 2:Theorem 1
Consider the summation f(n) consisting of basic functions :
f(n) = n +√n + n1.5+ lg n + n lg n + n2
We have seen that
lg n < √n < n <n lg n <n1.5 < n2
which means that the function n2 grows faster than all other
functions in the expression
Thus,
f(n) = n + √n + n1.5+ lg n + n lg n + n2
= O( max (n , √n , n1.5, lg n , n lg n , n2 ) )
= O(n2)
Theorem :
(
2)Suppose f1(
x
)= O(
g1(
x
)
)and f2(
x
)= O(
g2(
x
)
)then
(
f1f2)
(
x
) = O (
g1(
x
)
.g2(
x
)
)
Example :Theorem 2
If we have two nested loops,
inner loop = O(n) and outer loop = O(n), so:
The efficiency is O(n . n) = O(n2)
Theorem :Polynomial
(
3)Let ( ) = ∑ =
= a0 + a1x+ a2x
2+ …+ anx
n , where
ai are real numbers, Then F(
x
)= O(
x
n)
Example :Theorem 3
The polynomial
is order of x5 (or O(x5)).
The polynomial
is order of x199 (or O(x199) )
Theorem :Transitivity
(
4)If f(
x
)= O(
g (
x
)
)and h(
x
)˃ g(
x
)for sufficiently large x
0, it
follows that f (
x
)= O(
h (
x
)
)
Example : Theorem 4
x2+2x+1 = O(x2); and x3 > x2
 x2+2x+1 = O(x3)
Theorem :
(
1) Suppose f1(
x
)= O(
g1(
x
)
)and f2(
x
)= O(
g2(
x
)
)then
(
f1+f2)
(
x
) = O (
max
(
g1(
x
)
,g2(
x
)
)
(
2)Suppose f1(
x
)= O(
g1(
x
)
)and f2(
x
)= O(
g2(
x
)
)then
(
f1f2)
(
x
) = O (
g1(
x
)
.g2(
x
)
)
(
3)Let ( ) = ∑ =
= a0 + a1x+ a2x
2+ …+ anx
n , where
ai are real numbers, Then F(
x
)= O(
x
n).
(
4)If f(
x
)= O(
g (
x
)
)and h(
x
)˃ g(
x
)for sufficiently large x
0, it
follows that f (
x
)= O(
h (
x
)
)
28
NOTE:
• All logarithmic functions loga n belong to the
same class order of (log n) no matter what the
logarithm’
s base a > 1 is
• Exponential functions an have different orders of
growth for different a’
s
• order log n < order n
>0) < order an <
order n!< order nn
QUESTI
ON…
Cost Function: tA(n) = n2 + 200n + 10000
• Which term in the function is most important
(dominates)?
It depends on the size of n
• n = 20, tA(n) = 400 + 4000 + 10000
• The constant, is the dominating term
• n = 100, tA(n) = 10000 + 20000 + 10000
• 200n is the dominating term
• n = 1000, tA(n) = 1000000 + 200000 + 10000
• n2 is the dominant term
29
REFERENCES
Anany Levitin, Introduction to the design and analysis of
algorithms, 2nd Edition.
Chapter 1, sections 1.1, 1.2
Chapter 2, Sections 2.1,2.2
Kenneth H. Rosen, Discrete Mathematics and its applications,
7th Edition .
Chapter 3 Algorithms
Ad

More Related Content

Similar to 02 CS316_algorithms_Asymptotic_Notations(2).pdf (20)

Binary search design and ana algorithm.pptx
Binary search design and ana algorithm.pptxBinary search design and ana algorithm.pptx
Binary search design and ana algorithm.pptx
RajeshSukte1
 
big_oh
big_ohbig_oh
big_oh
Jonathan (JT) Cho
 
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 notation
zukun
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
AmayJaiswal4
 
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
allyn joy calcaben
 
Complete Book Lectures maths theory helpful for kids.ppt
Complete Book Lectures maths theory helpful for kids.pptComplete Book Lectures maths theory helpful for kids.ppt
Complete Book Lectures maths theory helpful for kids.ppt
AishaAnwar16
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
V.V.Vanniaperumal College for Women
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
Rajandeep Gill
 
stochastic processes assignment help
stochastic processes assignment helpstochastic processes assignment help
stochastic processes assignment help
Statistics Homework Helper
 
2_Asymptotic notations.pptx
2_Asymptotic notations.pptx2_Asymptotic notations.pptx
2_Asymptotic notations.pptx
dattakumar4
 
Asymptotic Growth of Functions
Asymptotic Growth of FunctionsAsymptotic Growth of Functions
Asymptotic Growth of Functions
DEVTYPE
 
02 asymp
02 asymp02 asymp
02 asymp
aparnabk7
 
6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf
6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf
6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf
dipanshutiwari1155
 
2-AnalysisOfAlgs.ppt
2-AnalysisOfAlgs.ppt2-AnalysisOfAlgs.ppt
2-AnalysisOfAlgs.ppt
TahseenEjaz3
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
S.Shayan Daneshvar
 
Prime numbers boundary
Prime numbers boundary Prime numbers boundary
Prime numbers boundary
Camilo Ulloa
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
sajinis3
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms I
Sri Prasanna
 
ASYMTOTIC NOTATION ON DATA STRUCTURE AND ALGORITHM
ASYMTOTIC NOTATION ON DATA STRUCTURE AND ALGORITHMASYMTOTIC NOTATION ON DATA STRUCTURE AND ALGORITHM
ASYMTOTIC NOTATION ON DATA STRUCTURE AND ALGORITHM
sd1898691
 
Binary search design and ana algorithm.pptx
Binary search design and ana algorithm.pptxBinary search design and ana algorithm.pptx
Binary search design and ana algorithm.pptx
RajeshSukte1
 
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 notation
zukun
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
AmayJaiswal4
 
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
allyn joy calcaben
 
Complete Book Lectures maths theory helpful for kids.ppt
Complete Book Lectures maths theory helpful for kids.pptComplete Book Lectures maths theory helpful for kids.ppt
Complete Book Lectures maths theory helpful for kids.ppt
AishaAnwar16
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
Rajandeep Gill
 
2_Asymptotic notations.pptx
2_Asymptotic notations.pptx2_Asymptotic notations.pptx
2_Asymptotic notations.pptx
dattakumar4
 
Asymptotic Growth of Functions
Asymptotic Growth of FunctionsAsymptotic Growth of Functions
Asymptotic Growth of Functions
DEVTYPE
 
6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf
6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf
6_12_13Asymptotic analysiskfnhlkjsbfbkjs.pdf
dipanshutiwari1155
 
2-AnalysisOfAlgs.ppt
2-AnalysisOfAlgs.ppt2-AnalysisOfAlgs.ppt
2-AnalysisOfAlgs.ppt
TahseenEjaz3
 
Prime numbers boundary
Prime numbers boundary Prime numbers boundary
Prime numbers boundary
Camilo Ulloa
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
sajinis3
 
Analysis Of Algorithms I
Analysis Of Algorithms IAnalysis Of Algorithms I
Analysis Of Algorithms I
Sri Prasanna
 
ASYMTOTIC NOTATION ON DATA STRUCTURE AND ALGORITHM
ASYMTOTIC NOTATION ON DATA STRUCTURE AND ALGORITHMASYMTOTIC NOTATION ON DATA STRUCTURE AND ALGORITHM
ASYMTOTIC NOTATION ON DATA STRUCTURE AND ALGORITHM
sd1898691
 

Recently uploaded (20)

The Business Conference and IT Resilience Summit Abu Dhabi, UAE - John Davison
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - John DavisonThe Business Conference and IT Resilience Summit Abu Dhabi, UAE - John Davison
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - John Davison
Continuity and Resilience
 
How to Integrate Telehealth Into Existing Workflows for Maximum Impact (1).pdf
How to Integrate Telehealth Into Existing Workflows for Maximum Impact (1).pdfHow to Integrate Telehealth Into Existing Workflows for Maximum Impact (1).pdf
How to Integrate Telehealth Into Existing Workflows for Maximum Impact (1).pdf
sundramvozo
 
Cost Structure of Hydrogen Vehicle Manufacturing Plant
Cost Structure of Hydrogen Vehicle Manufacturing PlantCost Structure of Hydrogen Vehicle Manufacturing Plant
Cost Structure of Hydrogen Vehicle Manufacturing Plant
surajimarc0777
 
Event Report - Informatica World 2025 - Off to be the System of Record for AI
Event Report - Informatica World 2025 - Off to be the System of Record for AIEvent Report - Informatica World 2025 - Off to be the System of Record for AI
Event Report - Informatica World 2025 - Off to be the System of Record for AI
Holger Mueller
 
BEONBIT 2025 New.pdf.....................
BEONBIT 2025 New.pdf.....................BEONBIT 2025 New.pdf.....................
BEONBIT 2025 New.pdf.....................
sudhir9132
 
How Jignesh Shah MCX Became the First Exchange to Be Listed on India’s Stock ...
How Jignesh Shah MCX Became the First Exchange to Be Listed on India’s Stock ...How Jignesh Shah MCX Became the First Exchange to Be Listed on India’s Stock ...
How Jignesh Shah MCX Became the First Exchange to Be Listed on India’s Stock ...
Jignesh Shah Case
 
Presented By NAVEENA | Digital Marketing
Presented By NAVEENA | Digital MarketingPresented By NAVEENA | Digital Marketing
Presented By NAVEENA | Digital Marketing
bnaveena69
 
Top Solar Panel Manufacturers in India and Photovoltaic Module Manufacturers....
Top Solar Panel Manufacturers in India and Photovoltaic Module Manufacturers....Top Solar Panel Manufacturers in India and Photovoltaic Module Manufacturers....
Top Solar Panel Manufacturers in India and Photovoltaic Module Manufacturers....
Insolation Energy
 
Introduction of E-commerce in ICT applications
Introduction of E-commerce in  ICT applicationsIntroduction of E-commerce in  ICT applications
Introduction of E-commerce in ICT applications
hammadakram562
 
A Brief Introduction About Quynh Keiser
A Brief Introduction  About Quynh KeiserA Brief Introduction  About Quynh Keiser
A Brief Introduction About Quynh Keiser
Quynh Keiser
 
Global Logistics Market Size, Share, Growth & Report (2025-2034)
Global Logistics Market Size, Share, Growth & Report (2025-2034)Global Logistics Market Size, Share, Growth & Report (2025-2034)
Global Logistics Market Size, Share, Growth & Report (2025-2034)
GeorgeButtler
 
Why Flow Switches Are Key to Efficient Water Management.pptx
Why Flow Switches Are Key to Efficient Water Management.pptxWhy Flow Switches Are Key to Efficient Water Management.pptx
Why Flow Switches Are Key to Efficient Water Management.pptx
Grid Controls
 
Green Corporate Minimalist Infographic Presentation Collection.pptx
Green Corporate Minimalist Infographic Presentation Collection.pptxGreen Corporate Minimalist Infographic Presentation Collection.pptx
Green Corporate Minimalist Infographic Presentation Collection.pptx
BhavadharaniR
 
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - AWS
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - AWSThe Business Conference and IT Resilience Summit Abu Dhabi, UAE - AWS
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - AWS
Continuity and Resilience
 
Electro-Optical Infrared (EO-IR) Systems Market Share & Growth Report | 2034
Electro-Optical Infrared (EO-IR) Systems Market Share & Growth Report | 2034Electro-Optical Infrared (EO-IR) Systems Market Share & Growth Report | 2034
Electro-Optical Infrared (EO-IR) Systems Market Share & Growth Report | 2034
janewatson684
 
Module I Introduction to Strategic Management .pptx
Module I Introduction to Strategic Management .pptxModule I Introduction to Strategic Management .pptx
Module I Introduction to Strategic Management .pptx
Rani Channamma University, Belagavi
 
Fillip Kosorukov - Passionate About Trading
Fillip Kosorukov - Passionate About TradingFillip Kosorukov - Passionate About Trading
Fillip Kosorukov - Passionate About Trading
Fillip Kosorukov
 
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - Sunil Mehta
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - Sunil MehtaThe Business Conference and IT Resilience Summit Abu Dhabi, UAE - Sunil Mehta
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - Sunil Mehta
Continuity and Resilience
 
The FedEx Effect; Innovation that Transformed Global Logistics
The FedEx Effect; Innovation that Transformed Global LogisticsThe FedEx Effect; Innovation that Transformed Global Logistics
The FedEx Effect; Innovation that Transformed Global Logistics
ramavisca
 
Eric Hannelius - A Serial Entrepreneur
Eric  Hannelius  -  A Serial EntrepreneurEric  Hannelius  -  A Serial Entrepreneur
Eric Hannelius - A Serial Entrepreneur
Eric Hannelius
 
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - John Davison
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - John DavisonThe Business Conference and IT Resilience Summit Abu Dhabi, UAE - John Davison
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - John Davison
Continuity and Resilience
 
How to Integrate Telehealth Into Existing Workflows for Maximum Impact (1).pdf
How to Integrate Telehealth Into Existing Workflows for Maximum Impact (1).pdfHow to Integrate Telehealth Into Existing Workflows for Maximum Impact (1).pdf
How to Integrate Telehealth Into Existing Workflows for Maximum Impact (1).pdf
sundramvozo
 
Cost Structure of Hydrogen Vehicle Manufacturing Plant
Cost Structure of Hydrogen Vehicle Manufacturing PlantCost Structure of Hydrogen Vehicle Manufacturing Plant
Cost Structure of Hydrogen Vehicle Manufacturing Plant
surajimarc0777
 
Event Report - Informatica World 2025 - Off to be the System of Record for AI
Event Report - Informatica World 2025 - Off to be the System of Record for AIEvent Report - Informatica World 2025 - Off to be the System of Record for AI
Event Report - Informatica World 2025 - Off to be the System of Record for AI
Holger Mueller
 
BEONBIT 2025 New.pdf.....................
BEONBIT 2025 New.pdf.....................BEONBIT 2025 New.pdf.....................
BEONBIT 2025 New.pdf.....................
sudhir9132
 
How Jignesh Shah MCX Became the First Exchange to Be Listed on India’s Stock ...
How Jignesh Shah MCX Became the First Exchange to Be Listed on India’s Stock ...How Jignesh Shah MCX Became the First Exchange to Be Listed on India’s Stock ...
How Jignesh Shah MCX Became the First Exchange to Be Listed on India’s Stock ...
Jignesh Shah Case
 
Presented By NAVEENA | Digital Marketing
Presented By NAVEENA | Digital MarketingPresented By NAVEENA | Digital Marketing
Presented By NAVEENA | Digital Marketing
bnaveena69
 
Top Solar Panel Manufacturers in India and Photovoltaic Module Manufacturers....
Top Solar Panel Manufacturers in India and Photovoltaic Module Manufacturers....Top Solar Panel Manufacturers in India and Photovoltaic Module Manufacturers....
Top Solar Panel Manufacturers in India and Photovoltaic Module Manufacturers....
Insolation Energy
 
Introduction of E-commerce in ICT applications
Introduction of E-commerce in  ICT applicationsIntroduction of E-commerce in  ICT applications
Introduction of E-commerce in ICT applications
hammadakram562
 
A Brief Introduction About Quynh Keiser
A Brief Introduction  About Quynh KeiserA Brief Introduction  About Quynh Keiser
A Brief Introduction About Quynh Keiser
Quynh Keiser
 
Global Logistics Market Size, Share, Growth & Report (2025-2034)
Global Logistics Market Size, Share, Growth & Report (2025-2034)Global Logistics Market Size, Share, Growth & Report (2025-2034)
Global Logistics Market Size, Share, Growth & Report (2025-2034)
GeorgeButtler
 
Why Flow Switches Are Key to Efficient Water Management.pptx
Why Flow Switches Are Key to Efficient Water Management.pptxWhy Flow Switches Are Key to Efficient Water Management.pptx
Why Flow Switches Are Key to Efficient Water Management.pptx
Grid Controls
 
Green Corporate Minimalist Infographic Presentation Collection.pptx
Green Corporate Minimalist Infographic Presentation Collection.pptxGreen Corporate Minimalist Infographic Presentation Collection.pptx
Green Corporate Minimalist Infographic Presentation Collection.pptx
BhavadharaniR
 
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - AWS
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - AWSThe Business Conference and IT Resilience Summit Abu Dhabi, UAE - AWS
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - AWS
Continuity and Resilience
 
Electro-Optical Infrared (EO-IR) Systems Market Share & Growth Report | 2034
Electro-Optical Infrared (EO-IR) Systems Market Share & Growth Report | 2034Electro-Optical Infrared (EO-IR) Systems Market Share & Growth Report | 2034
Electro-Optical Infrared (EO-IR) Systems Market Share & Growth Report | 2034
janewatson684
 
Fillip Kosorukov - Passionate About Trading
Fillip Kosorukov - Passionate About TradingFillip Kosorukov - Passionate About Trading
Fillip Kosorukov - Passionate About Trading
Fillip Kosorukov
 
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - Sunil Mehta
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - Sunil MehtaThe Business Conference and IT Resilience Summit Abu Dhabi, UAE - Sunil Mehta
The Business Conference and IT Resilience Summit Abu Dhabi, UAE - Sunil Mehta
Continuity and Resilience
 
The FedEx Effect; Innovation that Transformed Global Logistics
The FedEx Effect; Innovation that Transformed Global LogisticsThe FedEx Effect; Innovation that Transformed Global Logistics
The FedEx Effect; Innovation that Transformed Global Logistics
ramavisca
 
Eric Hannelius - A Serial Entrepreneur
Eric  Hannelius  -  A Serial EntrepreneurEric  Hannelius  -  A Serial Entrepreneur
Eric Hannelius - A Serial Entrepreneur
Eric Hannelius
 
Ad

02 CS316_algorithms_Asymptotic_Notations(2).pdf

  • 1. CS316: ALGORI THM S Lecture 2 ANALYSI SOFALGORI THM S 1 Prepared by: Assoc. Prof. Ensaf Hussein Presented by: Assoc. Prof. Wessam El-Behaidy Dr. Mohammed El-Said
  • 3. 3 BOUNDS(ASYMPTOTIC NOTATIONS) Critical factor for problem size n:  I S NOT the exact number of basic operations executed for given n  I S how number of basic operations grow s as n increases Consequently:  Focus on how performance grows as n     Ignore constant factors Call this:Asymptotic Order of Grow th
  • 4. Bounds describe the limiting behavior of algorithm complexity at large (n). They are: Worst Case:Upper Bound (Big O complexity) Best Case:Lower Bound (Big  complexity) Exact (Big  complexity) Approach:classify functions (i.e. of algorithms performance) based on their growth rates and divide into sets 4 BOUNDS (ASYMPTOTI C NOTATI ONS) W Q O
  • 5. O-NOTATION: DEFINITION Worst Case Upper Bound (Big O) class of functions (algorithms) f(n) that grow no faster than g(n) order of growth of f(n) ≤ order of growth of g(n) (within constant multiple). f(n) of the algorithm g(n) is one of growth functions
  • 7. O-NOTATION : x  O (x2)? Yes, c = 1, n0=1 works fine. 10x  O (x)? Yes, c = 11, n0=1 works fine. x2  O (x)? No, no matter what c and n0 we pick, cx2 > x for big enough x f (n)  O (g (n)) means:there are positive constants c and n0 such that f(n)  c g(n) for all values n  n0. Then:
  • 8. O-NOTATION : O(n3) O(n2) f(n) = n2.5 f(n) = 12n2 + n f(n) = n3.1 – n2 Hence,only the fastest-grow ing term in f matters
  • 9. O-NOTATI ON :EXAMPLES Example : Using basic definition, we show that 3n2 + 10n ϵ O(n2) Consider, 10 ≤ n for n ≥ 10 ( obvious ! ) 10n ≤ n2 for n ≥ 10 ( Multiplying both sides with n ) 3n2+10n ≤ 3n2 + n2 for n ≥ 10 ( Adding 3n2 to both sides ) =4n2 (Simplifying ) 3n2 + 10 n ≤ c.n2 for n ≥ n0 where c =4 and n0= 10 (Solution) Therefore, it follows from the basic definition that 3n2 +10n = O(n2) The choice of constant c is not unique. However, for each different c there is a corresponding value of n0 which satisfies the basic relation .This behavior is illustrated by the next example
  • 10. Example : In the preceding example it was shown that 3n2 + 10n ≤ c.n2 for c=4, n0=10. We now show that the relation holds true for a different value of c and corresponding n0. Consider n ≤ n2 for n ≥ 1 ( Obvious) 10n ≤ 10n2 for n≥ 1 (Multiplying both sides with 10 ) 3n2 +10 n ≤ 3n2 + 10n2 for n≥ 1 ( Adding 3n2 on both sides) 3n2 +10n ≤ 13n2 for n ≥ 1 ( Simplifying ) Or, 3n2 +10n ≤ c.n2, for n ≥ n0 where c=13, n0=1 ( Solution ) Therefore, by basic definition, 3n2 + 10n = O(n2)
  • 11. O-NOTATION EXAMPLE COMPARISON OF GROWTH RATES The results of analysis in the preceding examples are plotted in the next diagram. It can be seen that the function cg(n) =4n2 ( c= 4) overshoots the function f(n)= 3n2 + 10n for n0=10. Also, the function cg(n) =13n2 ( c =13 ) grows faster than f(n) = 3n2 + 10n for n0=1
  • 12. Growth of functions 13n2 and 4n2 versus the function 3n2 + 10 n Tight upper bound
  • 13. Ω-NOTATION: DEFINITION Best Case:Low er Bound (Big   class of functions f(n) that grow at least as fast as g(n) If order of growth of f(n) ≥ order of growth of g(n) (within constant multiple). f(n) ≥ c.g(n) for all n ≥ n0
  • 14. Ω-NOTATION: DEFINITION Let f and g be functions from the set of integers or the set of real numbers to the set of real numbers. We say that f(x) is  (g(x)) or f(x) =  (g(x)) (read as: “ f(x) is big-omega of g(x)” ) if there are constants C and n0 such that c.g(n) ≤ f(n) for all n ≥ n0 lim → ∞ ( ) ( ) = c , where c is a positive constant such that 0 < c ≤ ∞
  • 15. Ω-NOTATION BASIC METHOD Example: Using basic definition, we show that n3 ϵ Ω(n2). For, n3 ≥ n2 for n ≥ 0 i.e. we can select c=1 and n0= 0
  • 17. Θ-NOTATION: DEFINITION Exact (Big  complexity) Class of functions f(n) that grow at same rate as g(n) Order of growth of f(n) = order of growth of g(n) (within constant multiples). c2.g(n) ≤ f(n) ≤ c1.g(n) for all n ≥ n0
  • 18. Θ-NOTATION: DEFINITION Let f and g be functions from the set of integers or the set of real numbers to the set of real numbers. We say that f(x) = (g(x)) or f(x) is in order (g(x)) if f(x) = O(g(x)) and f(x) =  (g(x)). such that for some positive constants c1 , c2 and positive integer n0 , 0 < c2.g(n) ≤ f(n) ≤ c1.g(n) for all n ≥ n0 lim → ∞ ( ) ( ) = c , where c is a positive constant such that 0 < c < ∞
  • 19. Example: We show that ½ n (n-1) ϵ θ(n2). We need to prove that c2 g(n) ≤ F(n) ≤ c1 g(n) for all n ≥ no first, consider the upper bound, F(n) ≤ c1 g(n) ½ n2 – ½ n ≤ ½ n2 for all n ≥ 0. Second, consider the lower bound, F(n) ≥ c2 g(n) ½ n2 – ½ n ≥ ½ n2 – ½ n ½ n for all n ≥ 2. = ¼ n2. Hence we can select c2 = ¼ , c1= ½ , and n0 = 2. ½ n(n-1) = ½ n2 – ½ n
  • 21. 21 BOUNDS(ASYMPTOTIC NOTATIONS) W Q O f(n) ≤ c × g(n) for all n ≥ n0 n n0 c × g(n) f(n) f(n) є O(g(n)) f(n) ≥ c × g(n) for all n ≥ n0 n0 f(n) c × g(n) n f(n) є Ω(g(n)) c2×g(n) ≤ f(n) ≤ c1×g(n) for all n ≥ n0 n f(n) є Θ(g(n)) c1 × g(n) c2 × g(n) f(n) n0
  • 22. Theorem : ( 1) Suppose f1( x )= O( g1( x ) )and f2( x )= O( g2( x ) )then ( f1+f2) ( x ) = O ( max ( g1( x ) ,g2( x ) ) Example 1:Theorem 1 If our problem contains sorting inputs, then search within. Consider sorting algorithm= O(n2) comparisons and then binary search = O(log2n) comparisons, then: efficiency is O(max{n2, log2n}) = O(n2)
  • 23. Example 2:Theorem 1 Consider the summation f(n) consisting of basic functions : f(n) = n +√n + n1.5+ lg n + n lg n + n2 We have seen that lg n < √n < n <n lg n <n1.5 < n2 which means that the function n2 grows faster than all other functions in the expression Thus, f(n) = n + √n + n1.5+ lg n + n lg n + n2 = O( max (n , √n , n1.5, lg n , n lg n , n2 ) ) = O(n2)
  • 24. Theorem : ( 2)Suppose f1( x )= O( g1( x ) )and f2( x )= O( g2( x ) )then ( f1f2) ( x ) = O ( g1( x ) .g2( x ) ) Example :Theorem 2 If we have two nested loops, inner loop = O(n) and outer loop = O(n), so: The efficiency is O(n . n) = O(n2)
  • 25. Theorem :Polynomial ( 3)Let ( ) = ∑ = = a0 + a1x+ a2x 2+ …+ anx n , where ai are real numbers, Then F( x )= O( x n) Example :Theorem 3 The polynomial is order of x5 (or O(x5)). The polynomial is order of x199 (or O(x199) )
  • 26. Theorem :Transitivity ( 4)If f( x )= O( g ( x ) )and h( x )˃ g( x )for sufficiently large x 0, it follows that f ( x )= O( h ( x ) ) Example : Theorem 4 x2+2x+1 = O(x2); and x3 > x2  x2+2x+1 = O(x3)
  • 27. Theorem : ( 1) Suppose f1( x )= O( g1( x ) )and f2( x )= O( g2( x ) )then ( f1+f2) ( x ) = O ( max ( g1( x ) ,g2( x ) ) ( 2)Suppose f1( x )= O( g1( x ) )and f2( x )= O( g2( x ) )then ( f1f2) ( x ) = O ( g1( x ) .g2( x ) ) ( 3)Let ( ) = ∑ = = a0 + a1x+ a2x 2+ …+ anx n , where ai are real numbers, Then F( x )= O( x n). ( 4)If f( x )= O( g ( x ) )and h( x )˃ g( x )for sufficiently large x 0, it follows that f ( x )= O( h ( x ) )
  • 28. 28 NOTE: • All logarithmic functions loga n belong to the same class order of (log n) no matter what the logarithm’ s base a > 1 is • Exponential functions an have different orders of growth for different a’ s • order log n < order n >0) < order an < order n!< order nn
  • 29. QUESTI ON… Cost Function: tA(n) = n2 + 200n + 10000 • Which term in the function is most important (dominates)? It depends on the size of n • n = 20, tA(n) = 400 + 4000 + 10000 • The constant, is the dominating term • n = 100, tA(n) = 10000 + 20000 + 10000 • 200n is the dominating term • n = 1000, tA(n) = 1000000 + 200000 + 10000 • n2 is the dominant term 29
  • 30. REFERENCES Anany Levitin, Introduction to the design and analysis of algorithms, 2nd Edition. Chapter 1, sections 1.1, 1.2 Chapter 2, Sections 2.1,2.2 Kenneth H. Rosen, Discrete Mathematics and its applications, 7th Edition . Chapter 3 Algorithms
  翻译: