SlideShare ist ein Scribd-Unternehmen logo
1 von 40
Downloaden Sie, um offline zu lesen
CSE-304
Design & Analysis of Algorithm
Asymptotic Notation
2
Analyzing Algorithms
• Predict the amount of resources required:
• memory: how much space is needed?
• computational time: how fast the algorithm runs?
• FACT: running time grows with the size of the input
• Input size (number of elements in the input)
– Size of an array, polynomial degree, # of elements in a matrix, # of bits in
the binary representation of the input, vertices and edges in a graph
Def: Running time = the number of primitive operations (steps) executed
before termination
– Arithmetic operations (+, -, *), data movement, control, decision making
(if, while), comparison
3
Algorithm Analysis: Example
• Alg.: MIN (a[1], …, a[n])
m ← a[1];
for i ← 2 to n
if a[i] < m
then m ← a[i];
• Running time:
– the number of primitive operations (steps) executed
before termination
T(n) =1 [first step] + (n) [for loop] + (n-1) [if condition] +
(n-1) [the assignment in then] = 3n - 1
• Order (rate) of growth:
– The leading term of the formula
– Expresses the asymptotic behavior of the algorithm
4
Typical Running Time Functions
• 1 (constant running time):
– Instructions are executed once or a few times
• logN (logarithmic)
– A big problem is solved by cutting the original problem in smaller
sizes, by a constant fraction at each step
• N (linear)
– A small amount of processing is done on each input element
• N logN
– A problem is solved by dividing it into smaller problems, solving
them independently and combining the solution
5
Typical Running Time Functions
• N2 (quadratic)
– Typical for algorithms that process all pairs of data items (double
nested loops)
• N3 (cubic)
– Processing of triples of data (triple nested loops)
• NK (polynomial)
• 2N (exponential)
– Few exponential algorithms are appropriate for practical use
6
Growth of Functions
Complexity Graphs
log(n)
n
Complexity Graphs
log(n)
n
n
n log(n)
Complexity Graphs
n10
n log(n)
n3
n2
Complexity Graphs (log scale)
n10
n20
nn
1.1n
2n
3n
Algorithm Complexity
• Worst Case Complexity:
– the function defined by the maximum number of steps
taken on any instance of size n
• Best Case Complexity:
– the function defined by the minimum number of steps
taken on any instance of size n
• Average Case Complexity:
– the function defined by the average number of steps
taken on any instance of size n
Best, Worst, and Average Case Complexity
Worst Case
Complexity
Average Case
Complexity
Best Case
Complexity
Number
of steps
N
(input size)
Doing the Analysis
• It’s hard to estimate the running time exactly
– Best case depends on the input
– Average case is difficult to compute
– So we usually focus on worst case analysis
• Easier to compute
• Usually close to the actual running time
• Strategy: find a function (an equation) that, for large n, is an
upper bound to the actual function (actual number of steps,
memory usage, etc.)
Upper bound
Lower bound
Actual function
Motivation for Asymptotic Analysis
• An exact computation of worst-case running time
can be difficult
– Function may have many terms:
• 4n2 - 3n log n + 17.5 n - 43 n⅔ + 75
• An exact computation of worst-case running time
is unnecessary
– Remember that we are already approximating running
time by using RAM model
Classifying functions by their
Asymptotic Growth Rates (1/2)
• asymptotic growth rate, asymptotic order, or
order of functions
– Comparing and classifying functions that ignores
• constant factors and
• small inputs.
• The Sets big oh O(g), big theta (g), big omega
(g)
Classifying functions by their
Asymptotic Growth Rates (2/2)
• O(g(n)), Big-Oh of g of n, the Asymptotic Upper
Bound;
(g(n)), Theta of g of n, the Asymptotic Tight
Bound; and
(g(n)), Omega of g of n, the Asymptotic Lower
Bound.
17
Big-O
• What does it mean?
– If f(n) = O(n2), then:
• f(n) can be larger than n2 sometimes, but…
• We can choose some constant c and some value n0 such
that for every value of n larger than n0 : f(n) < cn2
• That is, for values larger than n0, f(n) is never more than a
constant multiplier greater than n2
• Or, in other words, f(n) does not grow more than a constant
factor faster than n2.
    
    0
0
allfor0
such thatandconstantspositiveexistthere:
nnncgnf
ncngOnf


18
Visualization of O(g(n))
n0
cg(n)
f(n)
19
Examples
– 2n2 = O(n3):
– n2 = O(n2):
– 1000n2+1000n = O(n2):
– n = O(n2):
2n2 ≤ cn3  2 ≤ cn  c = 1 and n0= 2
n2 ≤ cn2  c ≥ 1  c = 1 and n0= 1
1000n2+1000n ≤ cn2 ≤ cn2+ 1000n  c=1001 and n0 = 1
n ≤ cn2  cn ≥ 1  c = 1 and n0= 1
20
Big-O
 
 
 
 
 21.2
23
22
22
22
22
2075
000,150000,000,1
2
nOn
nOn
nOnn
nOn
nOn





21
More Big-O
• Prove that:
• Let c = 21 and n0 = 4
• 21n2 > 20n2 + 2n + 5 for all n > 4
n2 > 2n + 5 for all n > 4
TRUE
 22
5220 nOnn 
22
Tight bounds
• We generally want the tightest bound we can
find.
• While it is true that n2 + 7n is in O(n3), it is more
interesting to say that it is in O(n2)
23
Big Omega – Notation
• () – A lower bound
– n2 = (n)
– Let c = 1, n0 = 2
– For all n  2, n2 > 1  n
    
    0
0
allfor0
such thatandconstantspositiveexistthere:
nnncgnf
ncngnf


24
Visualization of (g(n))
n0
cg(n)
f(n)
25
-notation
• Big-O is not a tight upper bound. In other words
n = O(n2)
•  provides a tight bound
• In other words,
    
      021
021
allfor0
such thatand,,constantspositiveexistthere:
nnngcnfngc
nccngnf


              ngnfngOnfngnf  AND
26
Visualization of (g(n))
n0
c2g(n)
f(n)
c1g(n)
27
A Few More Examples
• n = O(n2) ≠ (n2)
• 200n2 = O(n2) = (n2)
• n2.5 ≠ O(n2) ≠ (n2)
28
Example 2
• Prove that:
• Let c = 21 and n0 = 10
• 21n3 > 20n3 + 7n + 1000 for all n > 10
n3 > 7n + 5 for all n > 10
TRUE, but we also need…
• Let c = 20 and n0 = 1
• 20n3 < 20n3 + 7n + 1000 for all n  1
TRUE
 33
1000720 nnn 
29
Example 3
• Show that
• Let c = 2 and n0 = 5
 nn
n 2O2 2

 
52
122
22
22
222
2
2
21
21
2







nn
n
n
n
n
n
n
nn
nn
nn

30
Asymptotic Notations - Examples
•  notation
– n2/2 – n/2
– (6n3 + 1)lgn/(n + 1)
– n vs. n2
•  notation
– n3 vs. n2
– n vs. logn
– n vs. n2
= (n2)
n ≠ (n2)
= (n2lgn)
• O notation
– 2n2 vs. n3
– n2 vs. n2
– n3 vs. nlogn
n3 = (n2)
n = (logn)
n  (n2)
2n2 = O(n3)
n2 = O(n2)
n3  O(nlgn)
31
Asymptotic Notations - Examples
• For each of the following pairs of functions, either f(n) is
O(g(n)), f(n) is Ω(g(n)), or f(n) = Θ(g(n)). Determine
which relationship is correct.
– f(n) = log n2; g(n) = log n + 5
– f(n) = n; g(n) = log n2
– f(n) = log log n; g(n) = log n
– f(n) = n; g(n) = log2 n
– f(n) = n log n + n; g(n) = log n
– f(n) = 10; g(n) = log 10
– f(n) = 2n; g(n) = 10n2
– f(n) = 2n; g(n) = 3n
f(n) =  (g(n))
f(n) = (g(n))
f(n) = O(g(n))
f(n) = (g(n))
f(n) = (g(n))
f(n) = (g(n))
f(n) = (g(n))
f(n) = O(g(n))
32
Simplifying Assumptions
• 1. If f(n) = O(g(n)) and g(n) = O(h(n)), then f(n) = O(h(n))
• 2. If f(n) = O(kg(n)) for any k > 0, then f(n) = O(g(n))
• 3. If f1(n) = O(g1(n)) and f2(n) = O(g2(n)),
• then f1(n) + f2(n) = O(max (g1(n), g2(n)))
• 4. If f1(n) = O(g1(n)) and f2(n) = O(g2(n)),
• then f1(n) * f2(n) = O(g1(n) * g2(n))
33
Example
• Code:
• a = b;
• Complexity:
34
Example
• Code:
• sum = 0;
• for (i=1; i <=n; i++)
• sum += n;
• Complexity:
35
Example
• Code:
• sum = 0;
• for (j=1; j<=n; j++)
• for (i=1; i<=j; i++)
• sum++;
• for (k=0; k<n; k++)
• A[k] = k;
• Complexity:
36
Example
• Code:
• sum1 = 0;
• for (i=1; i<=n; i++)
• for (j=1; j<=n; j++)
• sum1++;
• Complexity:
37
Example
• Code:
• sum2 = 0;
• for (i=1; i<=n; i++)
• for (j=1; j<=i; j++)
• sum2++;
• Complexity:
38
Example
• Code:
• sum1 = 0;
• for (k=1; k<=n; k*=2)
• for (j=1; j<=n; j++)
• sum1++;
• Complexity:
39
Example
• Code:
• sum2 = 0;
• for (k=1; k<=n; k*=2)
• for (j=1; j<=k; j++)
• sum2++;
• Complexity:
40
Recurrences
Def.: Recurrence = an equation or inequality that
describes a function in terms of its value on smaller
inputs, and one or more base cases
• E.g.: T(n) = T(n-1) + n
• Useful for analyzing recurrent algorithms
• Methods for solving recurrences
– Substitution method
– Recursion tree method
– Master method
– Iteration method

Weitere ähnliche Inhalte

Was ist angesagt?

Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notationsjayavignesh86
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.Tariq Khan
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sortMadhu Bala
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplicationKumar
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAdelina Ahadova
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm AnalysisMary Margarat
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxSyed Zaid Irshad
 
Randomizing quicksort algorith with example
Randomizing quicksort algorith with exampleRandomizing quicksort algorith with example
Randomizing quicksort algorith with examplemaamir farooq
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihmSajid Marwat
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lexAnusuya123
 
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dhrumil Panchal
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsArvind Krishnaa
 

Was ist angesagt? (20)

Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notations
 
Algorithm And analysis Lecture 03& 04-time complexity.
 Algorithm And analysis Lecture 03& 04-time complexity. Algorithm And analysis Lecture 03& 04-time complexity.
Algorithm And analysis Lecture 03& 04-time complexity.
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplication
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main Concepts
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
Randomizing quicksort algorith with example
Randomizing quicksort algorith with exampleRandomizing quicksort algorith with example
Randomizing quicksort algorith with example
 
Iterations and Recursions
Iterations and RecursionsIterations and Recursions
Iterations and Recursions
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Regular Grammar
Regular GrammarRegular Grammar
Regular Grammar
 
how to calclute time complexity of algortihm
how to calclute time complexity of algortihmhow to calclute time complexity of algortihm
how to calclute time complexity of algortihm
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 
A* algorithm
A* algorithmA* algorithm
A* algorithm
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)Dynamic Programming Code-Optimization Algorithm (Compiler Design)
Dynamic Programming Code-Optimization Algorithm (Compiler Design)
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 

Ähnlich wie Asymptotic Notation

1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptxpallavidhade2
 
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-zabistGatewayggg Testeru
 
04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptxarslanzaheer14
 
Algorithm Design and Analysis
Algorithm Design and AnalysisAlgorithm Design and Analysis
Algorithm Design and AnalysisReetesh Gupta
 
Introduction
IntroductionIntroduction
Introductionpilavare
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfAmayJaiswal4
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..KarthikeyaLanka1
 
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 pptsrushtiivp
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisAnindita Kundu
 
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
 
Chapter One.pdf
Chapter One.pdfChapter One.pdf
Chapter One.pdfabay golla
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsKrishnan MuthuManickam
 
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 .pdfssuser034ce1
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesSreedhar Chowdam
 
Recurrences
RecurrencesRecurrences
RecurrencesDEVTYPE
 

Ähnlich wie Asymptotic Notation (20)

1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx1_Asymptotic_Notation_pptx.pptx
1_Asymptotic_Notation_pptx.pptx
 
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
 
04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx04. Growth_Rate_AND_Asymptotic Notations_.pptx
04. Growth_Rate_AND_Asymptotic Notations_.pptx
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Algorithm Design and Analysis
Algorithm Design and AnalysisAlgorithm Design and Analysis
Algorithm Design and Analysis
 
Introduction
IntroductionIntroduction
Introduction
 
Big O Notation.ppt
Big O Notation.pptBig O Notation.ppt
Big O Notation.ppt
 
DAA_LECT_2.pdf
DAA_LECT_2.pdfDAA_LECT_2.pdf
DAA_LECT_2.pdf
 
Unit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdfUnit-1 DAA_Notes.pdf
Unit-1 DAA_Notes.pdf
 
DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..DS Unit-1.pptx very easy to understand..
DS Unit-1.pptx very easy to understand..
 
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
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysis
 
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...
 
Chapter One.pdf
Chapter One.pdfChapter One.pdf
Chapter One.pdf
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
 
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
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
 
Recurrences
RecurrencesRecurrences
Recurrences
 
Complexity analysis
Complexity analysisComplexity analysis
Complexity analysis
 

Kürzlich hochgeladen

KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...soginsider
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 

Kürzlich hochgeladen (20)

KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 

Asymptotic Notation

  • 1. CSE-304 Design & Analysis of Algorithm Asymptotic Notation
  • 2. 2 Analyzing Algorithms • Predict the amount of resources required: • memory: how much space is needed? • computational time: how fast the algorithm runs? • FACT: running time grows with the size of the input • Input size (number of elements in the input) – Size of an array, polynomial degree, # of elements in a matrix, # of bits in the binary representation of the input, vertices and edges in a graph Def: Running time = the number of primitive operations (steps) executed before termination – Arithmetic operations (+, -, *), data movement, control, decision making (if, while), comparison
  • 3. 3 Algorithm Analysis: Example • Alg.: MIN (a[1], …, a[n]) m ← a[1]; for i ← 2 to n if a[i] < m then m ← a[i]; • Running time: – the number of primitive operations (steps) executed before termination T(n) =1 [first step] + (n) [for loop] + (n-1) [if condition] + (n-1) [the assignment in then] = 3n - 1 • Order (rate) of growth: – The leading term of the formula – Expresses the asymptotic behavior of the algorithm
  • 4. 4 Typical Running Time Functions • 1 (constant running time): – Instructions are executed once or a few times • logN (logarithmic) – A big problem is solved by cutting the original problem in smaller sizes, by a constant fraction at each step • N (linear) – A small amount of processing is done on each input element • N logN – A problem is solved by dividing it into smaller problems, solving them independently and combining the solution
  • 5. 5 Typical Running Time Functions • N2 (quadratic) – Typical for algorithms that process all pairs of data items (double nested loops) • N3 (cubic) – Processing of triples of data (triple nested loops) • NK (polynomial) • 2N (exponential) – Few exponential algorithms are appropriate for practical use
  • 10. Complexity Graphs (log scale) n10 n20 nn 1.1n 2n 3n
  • 11. Algorithm Complexity • Worst Case Complexity: – the function defined by the maximum number of steps taken on any instance of size n • Best Case Complexity: – the function defined by the minimum number of steps taken on any instance of size n • Average Case Complexity: – the function defined by the average number of steps taken on any instance of size n
  • 12. Best, Worst, and Average Case Complexity Worst Case Complexity Average Case Complexity Best Case Complexity Number of steps N (input size)
  • 13. Doing the Analysis • It’s hard to estimate the running time exactly – Best case depends on the input – Average case is difficult to compute – So we usually focus on worst case analysis • Easier to compute • Usually close to the actual running time • Strategy: find a function (an equation) that, for large n, is an upper bound to the actual function (actual number of steps, memory usage, etc.) Upper bound Lower bound Actual function
  • 14. Motivation for Asymptotic Analysis • An exact computation of worst-case running time can be difficult – Function may have many terms: • 4n2 - 3n log n + 17.5 n - 43 n⅔ + 75 • An exact computation of worst-case running time is unnecessary – Remember that we are already approximating running time by using RAM model
  • 15. Classifying functions by their Asymptotic Growth Rates (1/2) • asymptotic growth rate, asymptotic order, or order of functions – Comparing and classifying functions that ignores • constant factors and • small inputs. • The Sets big oh O(g), big theta (g), big omega (g)
  • 16. Classifying functions by their Asymptotic Growth Rates (2/2) • O(g(n)), Big-Oh of g of n, the Asymptotic Upper Bound; (g(n)), Theta of g of n, the Asymptotic Tight Bound; and (g(n)), Omega of g of n, the Asymptotic Lower Bound.
  • 17. 17 Big-O • What does it mean? – If f(n) = O(n2), then: • f(n) can be larger than n2 sometimes, but… • We can choose some constant c and some value n0 such that for every value of n larger than n0 : f(n) < cn2 • That is, for values larger than n0, f(n) is never more than a constant multiplier greater than n2 • Or, in other words, f(n) does not grow more than a constant factor faster than n2.          0 0 allfor0 such thatandconstantspositiveexistthere: nnncgnf ncngOnf  
  • 19. 19 Examples – 2n2 = O(n3): – n2 = O(n2): – 1000n2+1000n = O(n2): – n = O(n2): 2n2 ≤ cn3  2 ≤ cn  c = 1 and n0= 2 n2 ≤ cn2  c ≥ 1  c = 1 and n0= 1 1000n2+1000n ≤ cn2 ≤ cn2+ 1000n  c=1001 and n0 = 1 n ≤ cn2  cn ≥ 1  c = 1 and n0= 1
  • 20. 20 Big-O          21.2 23 22 22 22 22 2075 000,150000,000,1 2 nOn nOn nOnn nOn nOn     
  • 21. 21 More Big-O • Prove that: • Let c = 21 and n0 = 4 • 21n2 > 20n2 + 2n + 5 for all n > 4 n2 > 2n + 5 for all n > 4 TRUE  22 5220 nOnn 
  • 22. 22 Tight bounds • We generally want the tightest bound we can find. • While it is true that n2 + 7n is in O(n3), it is more interesting to say that it is in O(n2)
  • 23. 23 Big Omega – Notation • () – A lower bound – n2 = (n) – Let c = 1, n0 = 2 – For all n  2, n2 > 1  n          0 0 allfor0 such thatandconstantspositiveexistthere: nnncgnf ncngnf  
  • 25. 25 -notation • Big-O is not a tight upper bound. In other words n = O(n2) •  provides a tight bound • In other words,            021 021 allfor0 such thatand,,constantspositiveexistthere: nnngcnfngc nccngnf                 ngnfngOnfngnf  AND
  • 27. 27 A Few More Examples • n = O(n2) ≠ (n2) • 200n2 = O(n2) = (n2) • n2.5 ≠ O(n2) ≠ (n2)
  • 28. 28 Example 2 • Prove that: • Let c = 21 and n0 = 10 • 21n3 > 20n3 + 7n + 1000 for all n > 10 n3 > 7n + 5 for all n > 10 TRUE, but we also need… • Let c = 20 and n0 = 1 • 20n3 < 20n3 + 7n + 1000 for all n  1 TRUE  33 1000720 nnn 
  • 29. 29 Example 3 • Show that • Let c = 2 and n0 = 5  nn n 2O2 2    52 122 22 22 222 2 2 21 21 2        nn n n n n n n nn nn nn 
  • 30. 30 Asymptotic Notations - Examples •  notation – n2/2 – n/2 – (6n3 + 1)lgn/(n + 1) – n vs. n2 •  notation – n3 vs. n2 – n vs. logn – n vs. n2 = (n2) n ≠ (n2) = (n2lgn) • O notation – 2n2 vs. n3 – n2 vs. n2 – n3 vs. nlogn n3 = (n2) n = (logn) n  (n2) 2n2 = O(n3) n2 = O(n2) n3  O(nlgn)
  • 31. 31 Asymptotic Notations - Examples • For each of the following pairs of functions, either f(n) is O(g(n)), f(n) is Ω(g(n)), or f(n) = Θ(g(n)). Determine which relationship is correct. – f(n) = log n2; g(n) = log n + 5 – f(n) = n; g(n) = log n2 – f(n) = log log n; g(n) = log n – f(n) = n; g(n) = log2 n – f(n) = n log n + n; g(n) = log n – f(n) = 10; g(n) = log 10 – f(n) = 2n; g(n) = 10n2 – f(n) = 2n; g(n) = 3n f(n) =  (g(n)) f(n) = (g(n)) f(n) = O(g(n)) f(n) = (g(n)) f(n) = (g(n)) f(n) = (g(n)) f(n) = (g(n)) f(n) = O(g(n))
  • 32. 32 Simplifying Assumptions • 1. If f(n) = O(g(n)) and g(n) = O(h(n)), then f(n) = O(h(n)) • 2. If f(n) = O(kg(n)) for any k > 0, then f(n) = O(g(n)) • 3. If f1(n) = O(g1(n)) and f2(n) = O(g2(n)), • then f1(n) + f2(n) = O(max (g1(n), g2(n))) • 4. If f1(n) = O(g1(n)) and f2(n) = O(g2(n)), • then f1(n) * f2(n) = O(g1(n) * g2(n))
  • 33. 33 Example • Code: • a = b; • Complexity:
  • 34. 34 Example • Code: • sum = 0; • for (i=1; i <=n; i++) • sum += n; • Complexity:
  • 35. 35 Example • Code: • sum = 0; • for (j=1; j<=n; j++) • for (i=1; i<=j; i++) • sum++; • for (k=0; k<n; k++) • A[k] = k; • Complexity:
  • 36. 36 Example • Code: • sum1 = 0; • for (i=1; i<=n; i++) • for (j=1; j<=n; j++) • sum1++; • Complexity:
  • 37. 37 Example • Code: • sum2 = 0; • for (i=1; i<=n; i++) • for (j=1; j<=i; j++) • sum2++; • Complexity:
  • 38. 38 Example • Code: • sum1 = 0; • for (k=1; k<=n; k*=2) • for (j=1; j<=n; j++) • sum1++; • Complexity:
  • 39. 39 Example • Code: • sum2 = 0; • for (k=1; k<=n; k*=2) • for (j=1; j<=k; j++) • sum2++; • Complexity:
  • 40. 40 Recurrences Def.: Recurrence = an equation or inequality that describes a function in terms of its value on smaller inputs, and one or more base cases • E.g.: T(n) = T(n-1) + n • Useful for analyzing recurrent algorithms • Methods for solving recurrences – Substitution method – Recursion tree method – Master method – Iteration method