DEV Community


Discussion on: What is Big O Notation?

robconery profile image
Rob Conery • Edited

Hi Jared - nice article. I wanted to echo what others have said that your example re alertColor() is always O(1) so you may want to tweak this:

What if state is not equal to danger? Then we perform multiple operations and the order of alertColor() is n.

The reason it's O(1) is that this algorithm will always perform the same tasks no matter the input (as there is no input).

I would encourage you to update the post so people don't get confused :).

A really helpful way to think about Big-O (in my opinion) is to ponder how many loops you have that loop over your input argument. One loop will always be O(n), nested loops are O(n2) and so on. No loops at all (as in your example) is always O(1).

I wrote about Big-O here: and I also wrote a big fat book about core programming concepts which is linked on my blog... didn't come here to be cheesy I promise!

nielsenjared profile image
Jared Nielsen Author

Hi Rob! The Impostor's Handbook is fantastic! I'm entirely self-taught and it helped me fill in gaps I didn't know I had.

Thank you for kindly flagging my error. Editorial oversight. Update in the works.


robconery profile image
Rob Conery

Cheers mate - no prob at all. This is tough stuff and my goodness did I get it wrong way too many times!