Sitemap
JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Member-only story

Big O Notation Explained

7 min readOct 20, 2021

--

Press enter or click to view image in full size
Big O Time Complexity
Big O Time Complexity, Image: Arek Jaworski

Introduction

In computer science, Big O notation is used to describe how an algorithm performs when the input size grows. The bigger the input, the more calculations (operations) our algorithm needs to perform.

We can measure time (how much more time an algorithm needs ) or space (how much more memory an algorithm needs).

In this article, we will focus on time complexity.

Before we actually begin we must understand one key concept. Big O is used to measure complexity of algorithms and not the actual, total execution time. We don’t need to check and count every single line of code! What we are looking are the key operations that make the algorithm to run slower or faster, e.g. loops or recursive calls.

Example: It’s obvious that printing out one character takes less time than printing out a whole page of text (especially on a real printer and not on the screen). Yet, in both cases, the complexity of the algorithm is the same. This may sound a bit counterintuitive to what we just stated — bigger input (i.e. longer text) — more print operations needed. Yet, if we convert this to code:

function print(text) {…

--

--

Arek Jaworski
Arek Jaworski

Written by Arek Jaworski

Software Architect — AWS/Node.JS/JavaScript Contractor and Tutor. Combing industry experience with research!

JavaScript in Plain English
JavaScript in Plain English

Published in JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.