## Big-O, In Anger

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 technical adjective, itâ€™s not a benchmarking system. Itâ€™s simply using math to describe the efficiency of what youâ€™ve created.

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)

February 17, 2022

## Whatâ€™s the Best Hashing Algorithm for Storing Passwords?

I’ve written a few authentication routines in my career and I’ve made sure to always hash sensitive user information. The thing is: I usually Googled which hashing algorithm to use and asked friends’ advice. Turns out there’s more than just bcrypt… and now I know when and why to choose something different.

What’s the Best Hashing Algorithm for Storing Passwords?

March 25, 2019

## WTF is Big O Notation?

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.

WTF is Big O Notation?

May 1, 2018

## The Logical Disaster of Null

I’m in the middle of writing the next volume of The Imposter’s Handbook and I found myself down a Rabbit Hole from the very outset: how can we, as programmers, justify the existence of null in our…

The Logical Disaster of Null