# Big O Notation

*February 09, 2022*| Theory

*Understanding Big O has many real world benefits, aside from passing a technical interview. In this post I'll provide a cheat sheet and some real world examples.*

When I started writing _*The Imposterâs Handbook*, this was the question that was in my head from the start: _*what the f*** is Big O and why should I care?* I remember giving myself a few weeks to jump in and figure it out but, fortunately, I found that it was pretty straightforward after putting a few smaller concepts together.

_* Big O is conceptual*. Many people want to qualify the efficiency of an algorithm based on the number of inputs. A common thought is

*if I have a list with 1 item it canât be O(n) because thereâs only 1 item so itâs O(1)*. This is an understandable approach, but

**Big O is a _**, itâs not a benchmarking system. Itâs simply using math to describe the efficiency of what youâve created.

*technical adjective*_* Big O is worst-case*, always. That means that even if you think youâre looking for is the very first thing in the set, Big O doesnât care, a loop-based find is still considered O(_

*n*). Thatâs because Big O is just a descriptive way of thinking about the code youâve written, not the inputs expected.

## THERE YOU HAVE IT

I find myself thinking about things in terms of Big O a lot. The cart example, above, happened to me just over a month ago and I needed to make sure that I was flexing the power of Redis as much as possible.

I donât want to turn this into a Redis commercial, but I will say that it (and systems like it) have a lot to offer when you start thinking about things in terms of _*time complexity*, which you should! ****Itâs not premature optimization to think about Big O upfront, itâs** _*** programming* and I donât mean to sound snotty about that! If you can clip an O(_

*n*) operation down to O(_

*log n*) then you should, donât you think?

So, quick review:

- Plucking an item from a list using an index or a key: O(1)
- Looping over a set of _
*n*items: O(_*n*) - A nested loop over _
*n*items: O(_*n^2*) - A divide and conquer algorithm: O(_
*log n*)

## Learn The Core CS Concepts Every Programmer Should Know - Free

In this **free, 52 page PDF** I'll share with you some of the skills and techniques I use on a daily basis.

Send me the free book!

We respect your privacy. Unsubscribe at any time.

##### Join over 15,000 programmers just like you and me

I have a problem when it comes to trying new things and learning about computer science stuff. I'm self-taught, so it's imperative I keep up with what's going on. I love sharing, so sign up and I'll send along what I've learned right to your inbox.