SlideShare a Scribd company logo
ANALYSIS AND DESIGN OF
ALGORITHM
Problems
❑Analysis of Algorithms involves determining the
amount of time, storage and/or other resources
❑Analyzing algorithms is called Asymptotic Analysis
❑Asymptotic Analysis evaluate the performance of an
algorithm
Time complexity
❑time complexity of an algorithm quantifies the amount of time taken by
an algorithm
❑ We can have three cases to analyze an algorithm:
1) Worst Case
2) Average Case
3) Best Case
❑ Assume the below algorithm using Python code:
Time Complexity of Algorithm (Analysis).pdf
❑ Worst Case Analysis: In the worst case analysis, we calculate upper
bound on running time of an algorithm.
Time Complexity of Algorithm (Analysis).pdf
❑ Worst Case Analysis: the case that causes maximum number of
operations to be executed.
❑ For Linear Search, the worst case happens when the element to be
searched is not present in the array. (example : search for number
8)
2 3 5 4 1 7 6
❑ Worst Case Analysis: When x is not present, the search() functions
compares it with all the elements of arr one by one.
❑ The worst case time complexity of linear search would be O(n).
Time Complexity of Algorithm (Analysis).pdf
❑ Average Case Analysis: we take all possible inputs and calculate
computing time for all of the inputs.
Time Complexity of Algorithm (Analysis).pdf
❑ Best Case Analysis: calculate lower bound on running time of an
algorithm.
❑ The best case time complexity of linear search would be O(1).
Time Complexity of Algorithm (Analysis).pdf
❑ Best Case Analysis: the case that causes minimum number of
operations to be executed.
❑ For Linear Search, the best case occurs when x is present at the first
location. (example : search for number 2)
❑ So time complexity in the best case would be Θ(1)
2 3 5 4 1 7 6
❑ Most of the times, we do worst case analysis to analyze algorithms.
❑ The average case analysis is not easy to do in most of the practical
cases and it is rarely done.
❑ The Best case analysis is bogus. Guaranteeing a lower bound on an
algorithm doesn’t provide any information.
1) Big O Notation: is an Asymptotic Notation for the worst case.
2) Ω Notation (omega notation): is an Asymptotic Notation for the best
case.
3) Θ Notation (theta notation) : is an Asymptotic Notation for the worst
case and the best case.
Big O Notation
1) O(1)
➢ Time complexity of a function (or set of statements) is considered as
O(1) if it doesn’t contain loop, recursion and call to any other
nonconstant time function. For example swap() function has O(1) time
complexity.
➢ A loop or recursion that runs a constant number of times is also
considered as O(1). For example the following loop is O(1).
2) O(n)
➢ Time Complexity of a loop is considered as O(n) if the loop variables is
incremented / decremented by a constant amount. For example the
following loop statements have O(n) time complexity.
Time Complexity of Algorithm (Analysis).pdf
❑ Another Example:
3) O(nc
)
➢ Time complexity of nested loops is equal to the number of times the
innermost statement is executed. For example the following loop
statements have O(n2
) time complexity
3) O(n2
)
❑ Another Example
4) O(Logn)
➢ Time Complexity of a loop is considered as O(Logn) if the loop
variables is divided / multiplied by a constant amount.
4) O(Logn)
➢ Another Example
5) O(LogLogn)
➢ Time Complexity of a loop is considered as O(LogLogn) if the loop
variables is reduced / increased exponentially by a constant.
5) O(LogLogn)
➢ Another Example
Time Complexity of Algorithm (Analysis).pdf
❑ How to combine time complexities of consecutive loops?
❑ Time complexity of above code is O(n) + O(m) which is O(n+m)
Time Complexity of Algorithm (Analysis).pdf
❑ Find the complexity of the below program:
❑ Solution: Time Complexity
is O(n). Even though
the innerloop is bounded
by n, but due to break
statement it is executed
only once.
www.YourCompany.com
© 2020 Companyname PowerPoint Business Theme. All Rights Reserved.

More Related Content

PDF
Algorithms Lecture 2: Analysis of Algorithms I
PPT
ALGORITHM AND ITS NOTATIONS,COMPLEXITIES.PPT
PPTX
Analysis of algorithms
PPTX
complexity big oh notation notation.pptx
PPTX
Design and analysis of algorithms unit1.pptx
PPTX
complex computer systems and its applications.pptx
PPTX
Measuring algorithm performance
PPT
Basics of data structure types of data structures
Algorithms Lecture 2: Analysis of Algorithms I
ALGORITHM AND ITS NOTATIONS,COMPLEXITIES.PPT
Analysis of algorithms
complexity big oh notation notation.pptx
Design and analysis of algorithms unit1.pptx
complex computer systems and its applications.pptx
Measuring algorithm performance
Basics of data structure types of data structures

Similar to Time Complexity of Algorithm (Analysis).pdf (20)

PPTX
Lecture 03 algorithm analysis
PPTX
Data Structure Algorithm -Algorithm Complexity
PPTX
ASYMPTOTIC NOTATION new topic in daa.pptx
PDF
Lecture Slides: Algorithm Analysis – Time & Space Complexity
PPT
18103010 algorithm complexity (iterative)
PPTX
BCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
PPTX
Analysis of Algorithms in Computer Science
PPTX
IObit Driver Booster Pro Crack Latest [2025-MAY]
PPTX
Driver Magician Lite Crack Latest [2025-MAY]
PDF
Asymptotic notations
PPTX
Searching Algorithms
PDF
Complexity
PDF
Design Analysis and Algorithm Module1.pdf
DOCX
Time Complexity Analysis in Data Structure.docx
PPTX
algorithm assignmenteeeeeee.pptx
PPT
Data Structure and Algorithms
PDF
12200223054_SrijanGho;sh_DAA_19.pdfkmkmm
PPTX
Asymptotic Notations
PPTX
Complexity analysis - The Big O Notation
PPTX
Algorithm.pptx
Lecture 03 algorithm analysis
Data Structure Algorithm -Algorithm Complexity
ASYMPTOTIC NOTATION new topic in daa.pptx
Lecture Slides: Algorithm Analysis – Time & Space Complexity
18103010 algorithm complexity (iterative)
BCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
Analysis of Algorithms in Computer Science
IObit Driver Booster Pro Crack Latest [2025-MAY]
Driver Magician Lite Crack Latest [2025-MAY]
Asymptotic notations
Searching Algorithms
Complexity
Design Analysis and Algorithm Module1.pdf
Time Complexity Analysis in Data Structure.docx
algorithm assignmenteeeeeee.pptx
Data Structure and Algorithms
12200223054_SrijanGho;sh_DAA_19.pdfkmkmm
Asymptotic Notations
Complexity analysis - The Big O Notation
Algorithm.pptx
Ad

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Machine learning based COVID-19 study performance prediction
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Cloud computing and distributed systems.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Advanced IT Governance
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Empathic Computing: Creating Shared Understanding
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Electronic commerce courselecture one. Pdf
Per capita expenditure prediction using model stacking based on satellite ima...
20250228 LYD VKU AI Blended-Learning.pptx
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Machine learning based COVID-19 study performance prediction
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Cloud computing and distributed systems.
“AI and Expert System Decision Support & Business Intelligence Systems”
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
GamePlan Trading System Review: Professional Trader's Honest Take
Dropbox Q2 2025 Financial Results & Investor Presentation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Advanced IT Governance
Spectral efficient network and resource selection model in 5G networks
Empathic Computing: Creating Shared Understanding
Reach Out and Touch Someone: Haptics and Empathic Computing
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Ad

Time Complexity of Algorithm (Analysis).pdf

  • 1. ANALYSIS AND DESIGN OF ALGORITHM
  • 3. ❑Analysis of Algorithms involves determining the amount of time, storage and/or other resources ❑Analyzing algorithms is called Asymptotic Analysis ❑Asymptotic Analysis evaluate the performance of an algorithm
  • 5. ❑time complexity of an algorithm quantifies the amount of time taken by an algorithm ❑ We can have three cases to analyze an algorithm: 1) Worst Case 2) Average Case 3) Best Case ❑ Assume the below algorithm using Python code:
  • 7. ❑ Worst Case Analysis: In the worst case analysis, we calculate upper bound on running time of an algorithm.
  • 9. ❑ Worst Case Analysis: the case that causes maximum number of operations to be executed. ❑ For Linear Search, the worst case happens when the element to be searched is not present in the array. (example : search for number 8) 2 3 5 4 1 7 6
  • 10. ❑ Worst Case Analysis: When x is not present, the search() functions compares it with all the elements of arr one by one.
  • 11. ❑ The worst case time complexity of linear search would be O(n).
  • 13. ❑ Average Case Analysis: we take all possible inputs and calculate computing time for all of the inputs.
  • 15. ❑ Best Case Analysis: calculate lower bound on running time of an algorithm.
  • 16. ❑ The best case time complexity of linear search would be O(1).
  • 18. ❑ Best Case Analysis: the case that causes minimum number of operations to be executed. ❑ For Linear Search, the best case occurs when x is present at the first location. (example : search for number 2) ❑ So time complexity in the best case would be Θ(1) 2 3 5 4 1 7 6 ❑ Most of the times, we do worst case analysis to analyze algorithms.
  • 19. ❑ The average case analysis is not easy to do in most of the practical cases and it is rarely done. ❑ The Best case analysis is bogus. Guaranteeing a lower bound on an algorithm doesn’t provide any information.
  • 20. 1) Big O Notation: is an Asymptotic Notation for the worst case. 2) Ω Notation (omega notation): is an Asymptotic Notation for the best case. 3) Θ Notation (theta notation) : is an Asymptotic Notation for the worst case and the best case.
  • 22. 1) O(1) ➢ Time complexity of a function (or set of statements) is considered as O(1) if it doesn’t contain loop, recursion and call to any other nonconstant time function. For example swap() function has O(1) time complexity.
  • 23. ➢ A loop or recursion that runs a constant number of times is also considered as O(1). For example the following loop is O(1).
  • 24. 2) O(n) ➢ Time Complexity of a loop is considered as O(n) if the loop variables is incremented / decremented by a constant amount. For example the following loop statements have O(n) time complexity.
  • 27. 3) O(nc ) ➢ Time complexity of nested loops is equal to the number of times the innermost statement is executed. For example the following loop statements have O(n2 ) time complexity
  • 30. 4) O(Logn) ➢ Time Complexity of a loop is considered as O(Logn) if the loop variables is divided / multiplied by a constant amount.
  • 32. 5) O(LogLogn) ➢ Time Complexity of a loop is considered as O(LogLogn) if the loop variables is reduced / increased exponentially by a constant.
  • 35. ❑ How to combine time complexities of consecutive loops? ❑ Time complexity of above code is O(n) + O(m) which is O(n+m)
  • 37. ❑ Find the complexity of the below program:
  • 38. ❑ Solution: Time Complexity is O(n). Even though the innerloop is bounded by n, but due to break statement it is executed only once.
  • 39. www.YourCompany.com © 2020 Companyname PowerPoint Business Theme. All Rights Reserved.