SlideShare a Scribd company logo
1 of 31
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.
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
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

Similar to Analysis of algorithms

Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematicalbabuk110
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptxNishaS88
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
Ch24 efficient algorithms
Ch24 efficient algorithmsCh24 efficient algorithms
Ch24 efficient algorithmsrajatmay1992
 
Algorithm 110801105245-phpapp01-120223065724-phpapp02
Algorithm 110801105245-phpapp01-120223065724-phpapp02Algorithm 110801105245-phpapp01-120223065724-phpapp02
Algorithm 110801105245-phpapp01-120223065724-phpapp02dhruv patel
 
Algorithm 110801105245-phpapp01
Algorithm 110801105245-phpapp01Algorithm 110801105245-phpapp01
Algorithm 110801105245-phpapp01Jay Patel
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm AnalysisMary Margarat
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsAbdullah Al-hazmy
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMSTanya Makkar
 
Measuring algorithm performance
Measuring algorithm performanceMeasuring algorithm performance
Measuring algorithm performanceHabitamuAsimare
 

Similar to Analysis of algorithms (20)

Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
Searching Algorithms
Searching AlgorithmsSearching Algorithms
Searching Algorithms
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Ch24 efficient algorithms
Ch24 efficient algorithmsCh24 efficient algorithms
Ch24 efficient algorithms
 
Algorithm 110801105245-phpapp01-120223065724-phpapp02
Algorithm 110801105245-phpapp01-120223065724-phpapp02Algorithm 110801105245-phpapp01-120223065724-phpapp02
Algorithm 110801105245-phpapp01-120223065724-phpapp02
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Algorithm 110801105245-phpapp01
Algorithm 110801105245-phpapp01Algorithm 110801105245-phpapp01
Algorithm 110801105245-phpapp01
 
Data Structures and Algorithm Analysis
Data Structures  and  Algorithm AnalysisData Structures  and  Algorithm Analysis
Data Structures and Algorithm Analysis
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Algorithm.pptx
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis tools
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB  (C, C++ Course Training Institute in KPHB, Kukatpall...Algorithm Class at KPHB  (C, C++ Course Training Institute in KPHB, Kukatpall...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpall...
 
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
Algorithm Class at KPHB (C, C++ Course Training Institute in KPHB, Kukatpally...
 
Unit 1
Unit 1Unit 1
Unit 1
 
Measuring algorithm performance
Measuring algorithm performanceMeasuring algorithm performance
Measuring algorithm performance
 

Recently uploaded

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Recently uploaded (20)

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

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.
  • 14.
  • 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
  • 16.
  • 17.
  • 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