Member-only story

A Beginner’s Guide to Big O Notation (Part 1)

Alison Quaglia
Better Programming
Published in
6 min readSep 14, 2020

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!

big o complexity chart

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.

chef Remy cooking ratatouille
Yum! Image credit: Pixar

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…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Alison Quaglia
Alison Quaglia

Written by Alison Quaglia

Software Engineer @ Pinterest. Bridging the gap between development and design. A believer in kindness above all things. 🌱

Write a response