SlideShare a Scribd company logo
1 of 16
Download to read offline
www.ieee.org
www.ieee.org
Big(O) Notation and Asymptotic
Time and Space Analysis
Chidera Anichebe
dera@ieee.org
www.ieee.org
What is Big O Notation?
▸ According to Wikipedia: “Big O notation is a mathematical notation that
describes the limiting behavior of a function when the argument tends towards
a particular value or infinity.
In computer science, big O notation is used to classify algorithms according to
how their run time or space requirements grow as the input size grows. In analytic
number theory, big O notation is often used to express a bound on the difference
between an arithmetical function and a better understood approximation; a
famous example of such a difference is the remainder term in the prime number
theorem. Big O notation is also used in many other fields to provide similar
estimates.”
2
www.ieee.org
Why is it useful?
▸ Big-O tells you the complexity of an algorithm in terms of the size of its inputs.
This is essential if you want to know how algorithms will scale as its input
becomes very large.
▸ If you're designing a big website and you have a lot of users, the time it takes
you to handle those requests is important. If you have lots of data and you
want to store it in a structure, you need to know how to do that efficiently if
you're going to write something that doesn't take a million years to run.
3
www.ieee.org
Why does it matter?
▸ Big-O tells you the complexity of an algorithm in terms of the size of its inputs.
This is essential if you want to know how algorithms will scale as its input
becomes very large.
▸ If you're designing a big website and you have a lot of users, the time it takes
you to handle those requests is important. If you have lots of data and you
want to store it in a structure, you need to know how to do that efficiently if
you're going to write something that doesn't take a million years to run.
4
www.ieee.org
Why does it matter?
▸ Efficiency of an Algorithm
▸ Time factor of an Algorithm
▸ Space complexity of an Algorithm
It describes…
5
www.ieee.org
Chart of common Big O notations
6
www.ieee.org
Order of Growth for common notations
7
www.ieee.org
Algorithm Analysis
Efficiency of an algorithm can be analyzed at two different stages, before
implementation and after implementation. They are the following:
- A priori analysis – This is a theoretical analysis of an algorithm. Efficiency of
an algorithm is measured by assuming that all other factors, for example,
processor speed, are constant and have no effect on the implementation.
- A posterior analysis – This is an empirical analysis of an algorithm. The
selected algorithm is implemented using programming language. This is then
executed on target’s machine. In this analysis, actual statistics like running
time and space required, are collected.
- Big O notation deals with a priori analysis
8
www.ieee.org
Algorithm analysis
▸ The time complexity of an algorithm represents the amount of time required by
the algorithm to run to completion. Time requirements can be defined as a
numerical function T(n), where T(n) can be measured as the number of steps,
provided each step takes constant time.
▸ For example, addition of two n-bit integers takes n steps. Consequently, the
total computational time is T(n) = c * n where c is the time taken for the
addition of two bits. Here, we observe that T(n) grows linearly as the input size
increases
Time Complexity
9
www.ieee.org
Algorithm analysis
▸ Space complexity of an algorithm represents the amount of memory space
required by an algorithm in its life cycle. The space required by an algorithm is
equal to the sum of the following two components:
- A fixed part that is a space required to store certain data and variables, that
are independent of the size of the problem. For example, simple variables and
constants used, program size etc.
- A variable part is a space required by variables, whose size depends on the
size of the problem. For example, dynamic memory allocation, recursion stack
frames etc.
▸ Space complexity S(p) of any algorithm P is S(p) = C + S(i), where C is the
fixed part and S(i) is the variable part of the algorithm, which depends on
instance characteristics.
Space Complexity
10
www.ieee.org
Asymptotic analysis
▸ Asymptotic analysis of an algorithm refers to defining the mathematical
boundaries of its run-time performance. Using asymptotic analysis, we can
very well conclude the best case, average case and worst case scenarios of
an algorithm.
▸ Asymptotic analysis is input bound i.e. if there’s no input to the algorithm, it is
concluded to work in a constant time. Other than the “input”, all other factors
are considered constant.
▸ Usually, the time required by an algorithm falls under three types –
- Best case – Minimum time required for program execution
- Average case – Average time required for program execution
- Worst case – Maximum time required for program execution
Best case, average case and worst case
11
www.ieee.org
Other forms of asymptotic notation
Big O, Omega and Theta notations
12
Omega (lower bound) Theta (tight bound) Big O (upper bound)
www.ieee.org
Common mistakes in Big O notation
13
This is O(a+b) not O(n)
This is O(ab) not O(n^2)
NOTE: Add the runtimes if you do x then y; Multiply the
runtimes if for each x you do y
www.ieee.org
PRACTICAL SESSION…
14
www.ieee.org
15
Questions?
www.ieee.org
www.ieee.org
Thank you!
Let’s connect
16
https://twitter.com/starlingvibe
https://linkedin.com/in/chideraanichebe
https://github.com/starlingvibes

More Related Content

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Big O Notation and Asymptotic analysis by Chidera Anichebe

  • 1. www.ieee.org www.ieee.org Big(O) Notation and Asymptotic Time and Space Analysis Chidera Anichebe dera@ieee.org
  • 2. www.ieee.org What is Big O Notation? ▸ According to Wikipedia: “Big O notation is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity. In computer science, big O notation is used to classify algorithms according to how their run time or space requirements grow as the input size grows. In analytic number theory, big O notation is often used to express a bound on the difference between an arithmetical function and a better understood approximation; a famous example of such a difference is the remainder term in the prime number theorem. Big O notation is also used in many other fields to provide similar estimates.” 2
  • 3. www.ieee.org Why is it useful? ▸ Big-O tells you the complexity of an algorithm in terms of the size of its inputs. This is essential if you want to know how algorithms will scale as its input becomes very large. ▸ If you're designing a big website and you have a lot of users, the time it takes you to handle those requests is important. If you have lots of data and you want to store it in a structure, you need to know how to do that efficiently if you're going to write something that doesn't take a million years to run. 3
  • 4. www.ieee.org Why does it matter? ▸ Big-O tells you the complexity of an algorithm in terms of the size of its inputs. This is essential if you want to know how algorithms will scale as its input becomes very large. ▸ If you're designing a big website and you have a lot of users, the time it takes you to handle those requests is important. If you have lots of data and you want to store it in a structure, you need to know how to do that efficiently if you're going to write something that doesn't take a million years to run. 4
  • 5. www.ieee.org Why does it matter? ▸ Efficiency of an Algorithm ▸ Time factor of an Algorithm ▸ Space complexity of an Algorithm It describes… 5
  • 6. www.ieee.org Chart of common Big O notations 6
  • 7. www.ieee.org Order of Growth for common notations 7
  • 8. www.ieee.org Algorithm Analysis Efficiency of an algorithm can be analyzed at two different stages, before implementation and after implementation. They are the following: - A priori analysis – This is a theoretical analysis of an algorithm. Efficiency of an algorithm is measured by assuming that all other factors, for example, processor speed, are constant and have no effect on the implementation. - A posterior analysis – This is an empirical analysis of an algorithm. The selected algorithm is implemented using programming language. This is then executed on target’s machine. In this analysis, actual statistics like running time and space required, are collected. - Big O notation deals with a priori analysis 8
  • 9. www.ieee.org Algorithm analysis ▸ The time complexity of an algorithm represents the amount of time required by the algorithm to run to completion. Time requirements can be defined as a numerical function T(n), where T(n) can be measured as the number of steps, provided each step takes constant time. ▸ For example, addition of two n-bit integers takes n steps. Consequently, the total computational time is T(n) = c * n where c is the time taken for the addition of two bits. Here, we observe that T(n) grows linearly as the input size increases Time Complexity 9
  • 10. www.ieee.org Algorithm analysis ▸ Space complexity of an algorithm represents the amount of memory space required by an algorithm in its life cycle. The space required by an algorithm is equal to the sum of the following two components: - A fixed part that is a space required to store certain data and variables, that are independent of the size of the problem. For example, simple variables and constants used, program size etc. - A variable part is a space required by variables, whose size depends on the size of the problem. For example, dynamic memory allocation, recursion stack frames etc. ▸ Space complexity S(p) of any algorithm P is S(p) = C + S(i), where C is the fixed part and S(i) is the variable part of the algorithm, which depends on instance characteristics. Space Complexity 10
  • 11. www.ieee.org Asymptotic analysis ▸ Asymptotic analysis of an algorithm refers to defining the mathematical boundaries of its run-time performance. Using asymptotic analysis, we can very well conclude the best case, average case and worst case scenarios of an algorithm. ▸ Asymptotic analysis is input bound i.e. if there’s no input to the algorithm, it is concluded to work in a constant time. Other than the “input”, all other factors are considered constant. ▸ Usually, the time required by an algorithm falls under three types – - Best case – Minimum time required for program execution - Average case – Average time required for program execution - Worst case – Maximum time required for program execution Best case, average case and worst case 11
  • 12. www.ieee.org Other forms of asymptotic notation Big O, Omega and Theta notations 12 Omega (lower bound) Theta (tight bound) Big O (upper bound)
  • 13. www.ieee.org Common mistakes in Big O notation 13 This is O(a+b) not O(n) This is O(ab) not O(n^2) NOTE: Add the runtimes if you do x then y; Multiply the runtimes if for each x you do y