SlideShare a Scribd company logo
BIG oIN
JAVASCRIPT
PART ONE
What is Big O?
Big O Notation is used to show how efficient an algorithm
or function is, in relative to its input size.
To measure the efficiency of an algorithm, we need to
consider two things:
Big-O captures the upper bound to show how much time or
memory an algorithm would require in the worst case
scenario as the input size grows.
● Time Complexity: How much time does it take to run
completely?
● Space Complexity: How much extra space does it require
in the process?
Each and every function or logic or methods or class
that we write falls under one of the Big O
expressions listed below,
O(1) 🤩 Best
O(Log n) 😃 Better
O(n)
O(n log n)
🙂 Normal
O(n^2)
🙃 Not Bad
☹ Bad
O(n^3) 😖 Worst
How Big O is expressed?
We programmers always come up with multiple solutions.
But how do we make sure that approach we took is the best?
This is where Big O comes into picture.
Let us consider an example to sum up the numbers from 1 to n.
// A function with O(n)
function addUpto(n) {
let total = 0;
for(let i=1; i<=n; i++){
total += i;
}
return total;
}
addUpto(10);
//55
// A function with O(1)
function addUpto(n) {
return n * ( n + 1 ) / 2;
}
addUpto(10);
//55
Why we need a Big O?
STAY AROUND
FOR THE
NEXT PART!
We will cover a bit more on the Big O.

More Related Content

PPT
Collatz Conjecture Research
PPT
Concept of c
PPTX
Data structures Lecture no. 4
PPTX
Big o notation
PPTX
Algorithm big o
PDF
The bog oh notation
PPTX
9 big o-notation
PDF
The Big O with Python
Collatz Conjecture Research
Concept of c
Data structures Lecture no. 4
Big o notation
Algorithm big o
The bog oh notation
9 big o-notation
The Big O with Python

Similar to What is Big O in JavaScript - Part-1 (20)

PPTX
Analysis of algorithms
PPT
Complexity analysis
PPTX
Analysis of algorithms
PPTX
Daa unit 6_efficiency of algorithms
PDF
Big omega
PPT
Slides_Unit04_ComplexityAnalysis- Big-O notation
PPTX
Asymptotic_Notations_v2_1709293258280.pptx
PPTX
Algorithm Complexity & Big-O Analysis
PPTX
CMSC 56 | Lecture 8: Growth of Functions
PPTX
Algorithm Analysis
PPTX
Dr hasany 2467_16649_1_lec-2-zabist
PPTX
Computational Complexity.pptx
PPT
Analysis of algo
PPTX
DAA Week 2 slide for design algorithm and analysis.pptx
PDF
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
PPTX
Unit ii algorithm
PPT
Algorithum Analysis
PDF
ESINF03-AlgAnalis.pdfESINF03-AlgAnalis.pdf
PPTX
CS 161 Section 1 Slides - Stanford University
PPTX
Asymptotic Notations
Analysis of algorithms
Complexity analysis
Analysis of algorithms
Daa unit 6_efficiency of algorithms
Big omega
Slides_Unit04_ComplexityAnalysis- Big-O notation
Asymptotic_Notations_v2_1709293258280.pptx
Algorithm Complexity & Big-O Analysis
CMSC 56 | Lecture 8: Growth of Functions
Algorithm Analysis
Dr hasany 2467_16649_1_lec-2-zabist
Computational Complexity.pptx
Analysis of algo
DAA Week 2 slide for design algorithm and analysis.pptx
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
Unit ii algorithm
Algorithum Analysis
ESINF03-AlgAnalis.pdfESINF03-AlgAnalis.pdf
CS 161 Section 1 Slides - Stanford University
Asymptotic Notations
Ad

More from Ideas2IT Technologies (20)

PDF
Version comaparison in JavaScript
PDF
Currying in JavaScript
PDF
JS Testing Frameworks
PDF
Cool usage of Encoding and Decoding a URI in Javascript
PDF
Iterables and Iterators in JavaScript
PDF
String comparison in javascript
PDF
JavaScript symbols
PDF
Json.parse() in JavaScript
PDF
Bubble sort in Java Script
PDF
Performance analysis in merging arrays - JavaScript
PDF
Nullish coalescing in JavaScript
PDF
Conditionally add keys in JavaScript
PDF
Variable hoisting in JavaScript
PDF
Formidable ES6 spread operator in JavaScript
PDF
Logging in JavaScript - Part-5
PDF
Logging in JavaScript - Part-4
PDF
Logging in JavaScript - Part-3
PDF
Logging in JavaScript - part-2
PDF
Logging in JavaScript - part-1
PDF
Array vs set in JavaScript
Version comaparison in JavaScript
Currying in JavaScript
JS Testing Frameworks
Cool usage of Encoding and Decoding a URI in Javascript
Iterables and Iterators in JavaScript
String comparison in javascript
JavaScript symbols
Json.parse() in JavaScript
Bubble sort in Java Script
Performance analysis in merging arrays - JavaScript
Nullish coalescing in JavaScript
Conditionally add keys in JavaScript
Variable hoisting in JavaScript
Formidable ES6 spread operator in JavaScript
Logging in JavaScript - Part-5
Logging in JavaScript - Part-4
Logging in JavaScript - Part-3
Logging in JavaScript - part-2
Logging in JavaScript - part-1
Array vs set in JavaScript
Ad

Recently uploaded (20)

PPTX
Computer Hardware tool: hand tools, diagnostics, ESD and cleaning tools
PDF
Best Practices for Rolling Out Competency Management Software.pdf
PDF
The Future of Smart Factories Why Embedded Analytics Leads the Way
PDF
How to Confidently Manage Project Budgets
PPTX
Dynamic Solutions Project Pitch Presentation
PDF
Comprehensive Salesforce Implementation Services.pdf
PDF
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
PPTX
Hire Expert Blazor Developers | Scalable Solutions by OnestopDA
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
PDF
Emergency Mustering solutions – A Brief overview
PPTX
Odoo Consulting Services by CandidRoot Solutions
PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
PDF
Rise With SAP partner in Mumbai.........
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
PDF
A Practical Breakdown of Automation in Project Management
PDF
Jenkins: An open-source automation server powering CI/CD Automation
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
PDF
PTS Company Brochure 2025 (1).pdf.......
Computer Hardware tool: hand tools, diagnostics, ESD and cleaning tools
Best Practices for Rolling Out Competency Management Software.pdf
The Future of Smart Factories Why Embedded Analytics Leads the Way
How to Confidently Manage Project Budgets
Dynamic Solutions Project Pitch Presentation
Comprehensive Salesforce Implementation Services.pdf
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
Hire Expert Blazor Developers | Scalable Solutions by OnestopDA
Materi_Pemrograman_Komputer-Looping.pptx
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
Emergency Mustering solutions – A Brief overview
Odoo Consulting Services by CandidRoot Solutions
A REACT POMODORO TIMER WEB APPLICATION.pdf
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
Rise With SAP partner in Mumbai.........
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
A Practical Breakdown of Automation in Project Management
Jenkins: An open-source automation server powering CI/CD Automation
Micromaid: A simple Mermaid-like chart generator for Pharo
PTS Company Brochure 2025 (1).pdf.......

What is Big O in JavaScript - Part-1

  • 2. What is Big O? Big O Notation is used to show how efficient an algorithm or function is, in relative to its input size. To measure the efficiency of an algorithm, we need to consider two things: Big-O captures the upper bound to show how much time or memory an algorithm would require in the worst case scenario as the input size grows. ● Time Complexity: How much time does it take to run completely? ● Space Complexity: How much extra space does it require in the process?
  • 3. Each and every function or logic or methods or class that we write falls under one of the Big O expressions listed below, O(1) 🤩 Best O(Log n) 😃 Better O(n) O(n log n) 🙂 Normal O(n^2) 🙃 Not Bad ☹ Bad O(n^3) 😖 Worst How Big O is expressed?
  • 4. We programmers always come up with multiple solutions. But how do we make sure that approach we took is the best? This is where Big O comes into picture. Let us consider an example to sum up the numbers from 1 to n. // A function with O(n) function addUpto(n) { let total = 0; for(let i=1; i<=n; i++){ total += i; } return total; } addUpto(10); //55 // A function with O(1) function addUpto(n) { return n * ( n + 1 ) / 2; } addUpto(10); //55 Why we need a Big O?
  • 5. STAY AROUND FOR THE NEXT PART! We will cover a bit more on the Big O.