SlideShare a Scribd company logo
Analysis of
algorithms
Ruuby show and tell
Why is it important?
● Efficiency Matters
○ Efficient algorithms save time and resources.
○ Essential for applications with large datasets or real-time processing.
● Predicting Performance
○ Analysis enables predictions of algorithm behavior with increasing input sizes.
○ Critical for anticipating and addressing performance issues.
● Comparative Evaluation
○ Facilitates the comparison of algorithms solving the same problem.
○ Identifies trade-offs and helps choose the most suitable solution.
● Optimization Opportunities
○ Identifying bottlenecks leads to optimization opportunities.
○ Enhancing algorithm efficiency improves overall system performance.
Algorithms complexity
How to evaluate the complexity of an
algorithm?
In computer science, we analyze the time or space complexity of algorithms by considering their
input size and using asymptotic notations.
● Time complexity
○ Counting Operations: Analyze the number of basic operations (such as comparisons,
assignments, and arithmetic operations) executed by the algorithm as a function of the
input size.
● Space complexity
○ Memory Usage: Analyze the amount of memory space required by the algorithm in
terms of the input size.
Asymptotic notations
● Does not measure the actual running time.
● Takes in account only the most significant terms and ignore others.
● Expresses how the time or space taken increases when the input size tends to infinity.
Most commonly used notations
● Omega notation - (Ω)
○ Represents the best case scenario.
○ The minimum amount of time or space an algorithm may need to solve a problem.
● Theta notation - (Θ)
○ Represents the average-case scenario.
○ The amount of time or space an algorithm typically needs to solve a problem.
● Big O notation - (O)
○ Represents the worst-case scenario.
○ The maximum amount of time or space an algorithm may need to solve a problem.
Big O notation
How to evaluate an algorithm complexity in
terms of big O notation?
1. Count the number of operations performed of each program segment in terms of input
size.
2. Ignore the constant values.
3. Take in account only the most dominant terms.
4. Express the result using big O notation.
Find an element in array - what is the worst-
case scenario?
Find an element in array - worst-case
scenario.
Find an element in array - worst-case
scenario.
T(N) = 3N + 1 => O(N)
The function has O(N) time complexity and we call it a linear search.
Big O formal definition
f(n) = O(g(n))
if there exist positive integer numbers M and n0 such that
f(n) <= M * g(n)
for all n >= n0.
Common complexities
● O(1) - constant complexity.
● O(log N) - logarithmic complexity.
● O(N) - linear complexity.
● O(N log N) - linearithmic complexity.
● O(N^2) - quadratic complexity.
● O(2^N) - exponential complexity.
● O(N!) - factorial complexity.
Analysis of algorithms
Analysing bubble sort algorithm
1. Implement the algorithm.
2. Count the number of operations in terms of input size..
3. Construct a function with all operations.
4. Discard constants and minor terms.
5. Express the worst-case scenario in big O notation.
https://en.wikipedia.org/wiki/Bubble_sort
Analysis of algorithms
Analysis of algorithms
Construct a time complexity function of
bubble sort in terms of the input size
T(N) = N + 3N * (2N + N + N + N)
=> T(N) = N + 3N * 5N
Discard constants and minor terms of bubble
sort time complexity function.
T(N) = N + 3N * 5N
=> T(N) = N * N
=> T(N) = N^2
The worst-case scenario of bubble sort in big
O notation.
T(N) = N^2
=> O(N^2)
The function has O(N^2) time complexity or quadratic time complexity.
Time complexity of common
JavaScript operations
Objects
● Set/get property value - O(1) in vast majority of cases
● Copy an object ({ …obj }) - O(N) N depends on the number of keys
● Getting list of object keys, values, entries - O(N)
Arrays
● Set/get value on index arr[i] - O(1)
● push - O(1)
● pop - O(1)
● copy an array ([ …arr ]) / arr.slice() - O(N)
● splice - O(N)
● shift/unshift - O(N)
● map/reduce/filter/some - O(N)
● find/includes/indexOf - O(N)
● sort - O(N log N)
Strings
● Get a character at index - O(1)
● String concatenation - by a book O(N), but it is optimized to O(1)
● includes/indexOf - O(N)
Sets / Maps
● Add an element - O(1)
● Check if element/key is in the set/map - O(1)
● Remove an element - O(1)
● Construct set/map from array - O(N)
Pros and Cons of
big O notation
Pros of Big O Notation
● Simplicity and Abstraction
○ Big O notation provides a simple and abstract way to describe the efficiency of an algorithm
without getting into the details of hardware, programming language, or constant factors.
● Comparative Analysis
○ It allows for easy comparison between different algorithms by focusing on their growth rates.
This makes it easier to choose the most efficient algorithm for a specific problem.
● Standardized Terminology
○ It provides a standardized and widely accepted way of expressing the time and space
complexity of algorithms, fostering a common language for discussing and analyzing
algorithms.
Cons of Big O Notation
● Constant Factors Ignored
○ Big O notation does not consider constant factors or lower-order terms, which means it may
not capture the actual performance differences between algorithms with similar growth rates
for small input sizes.
● Non-Uniform Growth Rates
○ It treats all operations as equal, but in reality, different operations can have different execution
times. This can lead to inaccuracies in predicting the actual performance of an algorithm.
● Does Not Consider Parallelism
○ With the increasing use of parallel processing and multi-core architectures, Big O notation
may not accurately reflect the true efficiency of an algorithm in a parallel computing
environment.
Resources
Analysis of algorithms resources
● https://en.wikipedia.org/wiki/Big_O_notation
● https://www.geeksforgeeks.org/asymptotic-notation-and-analysis-based-on-input-
size-of-algorithms/
● https://www.freecodecamp.org/news/big-o-notation-why-it-matters-and-why-it-
doesnt-1674cfa8a23c/
● https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-
notation/a/asymptotic-notation
Thank you!
Asen Bozhilov

More Related Content

PPTX
Les enjeux éthique de l'IA
PPTX
Les drivers de motivation.pptx
PPT
Walt Disney
PDF
L’intelligence émotionnelle au service de la communication. Par Jean-Yves Girin.
PDF
Decrypter le-langage-du-corps
PPTX
Etude RH et digitalisation de l’entreprise
PDF
Design thinking
PPTX
IBM Design Thinking - Hen shkedi
Les enjeux éthique de l'IA
Les drivers de motivation.pptx
Walt Disney
L’intelligence émotionnelle au service de la communication. Par Jean-Yves Girin.
Decrypter le-langage-du-corps
Etude RH et digitalisation de l’entreprise
Design thinking
IBM Design Thinking - Hen shkedi

What's hot (9)

PDF
Walt Disney Documentary
PDF
Design Thinking?
PDF
Customers' Job To Be Done
PPTX
Walt disney
PDF
Surveys for communicators
PPTX
Better meetings through strategic collaboration and humble inquiry
PDF
Cours communication
PDF
Agile 2012 - leadership agility workshop slides -- final.pptx
PPT
Gerer le stress
Walt Disney Documentary
Design Thinking?
Customers' Job To Be Done
Walt disney
Surveys for communicators
Better meetings through strategic collaboration and humble inquiry
Cours communication
Agile 2012 - leadership agility workshop slides -- final.pptx
Gerer le stress
Ad

Similar to Analysis of algorithms (20)

PPTX
BCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
PDF
Algorithm Analysis.pdf
PPT
Basics of data structure types of data structures
PDF
Design Analysis and Algorithm Module1.pdf
PPTX
Unit ii algorithm
PPTX
Searching Algorithms
PDF
12200223054_SrijanGho;sh_DAA_19.pdfkmkmm
PDF
Data Structure & Algorithms - Mathematical
PPTX
DAA-Unit1.pptx
PPTX
Data Structure Algorithm -Algorithm Complexity
PPTX
Asymptotic Notations
PDF
Ch24 efficient algorithms
PPTX
Algorithm for the DAA agscsnak javausmagagah
PDF
Algorithm
PDF
Algorithm 110801105245-phpapp01
PDF
Algorithm 110801105245-phpapp01-120223065724-phpapp02
PPTX
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
PPT
Data Structures and Algorithm Analysis
PPTX
design analysis of algorithmaa unit 1.pptx
PPTX
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
BCSE202Lkkljkljkbbbnbnghghjghghghghghghghgh
Algorithm Analysis.pdf
Basics of data structure types of data structures
Design Analysis and Algorithm Module1.pdf
Unit ii algorithm
Searching Algorithms
12200223054_SrijanGho;sh_DAA_19.pdfkmkmm
Data Structure & Algorithms - Mathematical
DAA-Unit1.pptx
Data Structure Algorithm -Algorithm Complexity
Asymptotic Notations
Ch24 efficient algorithms
Algorithm for the DAA agscsnak javausmagagah
Algorithm
Algorithm 110801105245-phpapp01
Algorithm 110801105245-phpapp01-120223065724-phpapp02
Data Structures and Agorithm: DS 22 Analysis of Algorithm.pptx
Data Structures and Algorithm Analysis
design analysis of algorithmaa unit 1.pptx
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
Ad

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation theory and applications.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
cuic standard and advanced reporting.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPT
Teaching material agriculture food technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Cloud computing and distributed systems.
PDF
Electronic commerce courselecture one. Pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation theory and applications.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
cuic standard and advanced reporting.pdf
sap open course for s4hana steps from ECC to s4
Digital-Transformation-Roadmap-for-Companies.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
Spectral efficient network and resource selection model in 5G networks
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Teaching material agriculture food technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Review of recent advances in non-invasive hemoglobin estimation
Cloud computing and distributed systems.
Electronic commerce courselecture one. Pdf
20250228 LYD VKU AI Blended-Learning.pptx

Analysis of algorithms

  • 2. Why is it important? ● Efficiency Matters ○ Efficient algorithms save time and resources. ○ Essential for applications with large datasets or real-time processing. ● Predicting Performance ○ Analysis enables predictions of algorithm behavior with increasing input sizes. ○ Critical for anticipating and addressing performance issues. ● Comparative Evaluation ○ Facilitates the comparison of algorithms solving the same problem. ○ Identifies trade-offs and helps choose the most suitable solution. ● Optimization Opportunities ○ Identifying bottlenecks leads to optimization opportunities. ○ Enhancing algorithm efficiency improves overall system performance.
  • 4. How to evaluate the complexity of an algorithm? In computer science, we analyze the time or space complexity of algorithms by considering their input size and using asymptotic notations. ● Time complexity ○ Counting Operations: Analyze the number of basic operations (such as comparisons, assignments, and arithmetic operations) executed by the algorithm as a function of the input size. ● Space complexity ○ Memory Usage: Analyze the amount of memory space required by the algorithm in terms of the input size.
  • 5. Asymptotic notations ● Does not measure the actual running time. ● Takes in account only the most significant terms and ignore others. ● Expresses how the time or space taken increases when the input size tends to infinity.
  • 6. Most commonly used notations ● Omega notation - (Ω) ○ Represents the best case scenario. ○ The minimum amount of time or space an algorithm may need to solve a problem. ● Theta notation - (Θ) ○ Represents the average-case scenario. ○ The amount of time or space an algorithm typically needs to solve a problem. ● Big O notation - (O) ○ Represents the worst-case scenario. ○ The maximum amount of time or space an algorithm may need to solve a problem.
  • 8. How to evaluate an algorithm complexity in terms of big O notation? 1. Count the number of operations performed of each program segment in terms of input size. 2. Ignore the constant values. 3. Take in account only the most dominant terms. 4. Express the result using big O notation.
  • 9. Find an element in array - what is the worst- case scenario?
  • 10. Find an element in array - worst-case scenario.
  • 11. Find an element in array - worst-case scenario. T(N) = 3N + 1 => O(N) The function has O(N) time complexity and we call it a linear search.
  • 12. Big O formal definition f(n) = O(g(n)) if there exist positive integer numbers M and n0 such that f(n) <= M * g(n) for all n >= n0.
  • 13. Common complexities ● O(1) - constant complexity. ● O(log N) - logarithmic complexity. ● O(N) - linear complexity. ● O(N log N) - linearithmic complexity. ● O(N^2) - quadratic complexity. ● O(2^N) - exponential complexity. ● O(N!) - factorial complexity.
  • 15. Analysing bubble sort algorithm 1. Implement the algorithm. 2. Count the number of operations in terms of input size.. 3. Construct a function with all operations. 4. Discard constants and minor terms. 5. Express the worst-case scenario in big O notation. https://en.wikipedia.org/wiki/Bubble_sort
  • 18. Construct a time complexity function of bubble sort in terms of the input size T(N) = N + 3N * (2N + N + N + N) => T(N) = N + 3N * 5N
  • 19. Discard constants and minor terms of bubble sort time complexity function. T(N) = N + 3N * 5N => T(N) = N * N => T(N) = N^2
  • 20. The worst-case scenario of bubble sort in big O notation. T(N) = N^2 => O(N^2) The function has O(N^2) time complexity or quadratic time complexity.
  • 21. Time complexity of common JavaScript operations
  • 22. Objects ● Set/get property value - O(1) in vast majority of cases ● Copy an object ({ …obj }) - O(N) N depends on the number of keys ● Getting list of object keys, values, entries - O(N)
  • 23. Arrays ● Set/get value on index arr[i] - O(1) ● push - O(1) ● pop - O(1) ● copy an array ([ …arr ]) / arr.slice() - O(N) ● splice - O(N) ● shift/unshift - O(N) ● map/reduce/filter/some - O(N) ● find/includes/indexOf - O(N) ● sort - O(N log N)
  • 24. Strings ● Get a character at index - O(1) ● String concatenation - by a book O(N), but it is optimized to O(1) ● includes/indexOf - O(N)
  • 25. Sets / Maps ● Add an element - O(1) ● Check if element/key is in the set/map - O(1) ● Remove an element - O(1) ● Construct set/map from array - O(N)
  • 26. Pros and Cons of big O notation
  • 27. Pros of Big O Notation ● Simplicity and Abstraction ○ Big O notation provides a simple and abstract way to describe the efficiency of an algorithm without getting into the details of hardware, programming language, or constant factors. ● Comparative Analysis ○ It allows for easy comparison between different algorithms by focusing on their growth rates. This makes it easier to choose the most efficient algorithm for a specific problem. ● Standardized Terminology ○ It provides a standardized and widely accepted way of expressing the time and space complexity of algorithms, fostering a common language for discussing and analyzing algorithms.
  • 28. Cons of Big O Notation ● Constant Factors Ignored ○ Big O notation does not consider constant factors or lower-order terms, which means it may not capture the actual performance differences between algorithms with similar growth rates for small input sizes. ● Non-Uniform Growth Rates ○ It treats all operations as equal, but in reality, different operations can have different execution times. This can lead to inaccuracies in predicting the actual performance of an algorithm. ● Does Not Consider Parallelism ○ With the increasing use of parallel processing and multi-core architectures, Big O notation may not accurately reflect the true efficiency of an algorithm in a parallel computing environment.
  • 30. Analysis of algorithms resources ● https://en.wikipedia.org/wiki/Big_O_notation ● https://www.geeksforgeeks.org/asymptotic-notation-and-analysis-based-on-input- size-of-algorithms/ ● https://www.freecodecamp.org/news/big-o-notation-why-it-matters-and-why-it- doesnt-1674cfa8a23c/ ● https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic- notation/a/asymptotic-notation