Member-only story
Big O Notation Explained
Big O notation explained, without any complex maths, using simple examples!
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) {…
