Member-only story
A Beginner’s Guide to Big O Notation (Part 1)
An introduction to time complexity with help from Ratatouille
When we write code, it’s important to understand how our choice of code impacts the speed and performance of the program we’re creating. Big O Notation is a way to classify how quickly the runtime of the algorithm/number of operations or space increases in relation to the input n
. It looks at the worst case scenario, assuming every possible element is touched on as the algorithm is written.
There are seven classifications in Big O Notation, ranging from fantastic, fast and/or space efficient solutions that remain constant despite the input size, to absolutely terrible, please-don’t-ever-use-these solutions!

Understanding how different data structures and algorithms fit into this Big O complexity gradient can help you select the right ones and optimize your code at work — or for a tech coding interview, perhaps.
O(1) Constant Time
Let’s say that you’re Chef Remy and you’ve been asked to cook your world famous Ratatouille.

The first thing you do is gather the ingredients, spices and herbs to prepare the dish. The kitchen is your second home — you know exactly where to find everything you need:
let kitchen = {
vegetables: {
broccoli: {name: "broccoli", ...},
zucchini: {name: "zucchini", ...},
eggplant: {name: "eggplant", ...},
carrot: {name: "carrot", ...},
squash: {name: "squash", ...},
tomato: {name: "tomato", ...},
radish: {name: "radish", ...},
cabbage: {name: "cabbage", ...},
redPepper: {name: "redPepper", ...}
},
seasoning: {
onion: {name: "onion", ...},
garlic: {name: "garlic", ...},
basil: {name: "basil", ...},
oregano: {name: "oregano", ...},
herbesDeProvence: {name: "herbesDeProvence", ...},
sage: {name: "sage", ...},
ginger: {name: "ginger", ...}
}
}
You don’t need everything in the kitchen for this recipe — broccoli and ginger…