Algorithm Complexity and Big O Notation

⭐️ 👀 2023 WEB DEVELOPMENT BOOTCAMP starting in days! Join the waiting list to reserve your spot in my 10-weeks cohort course and learn the fundamentals, HTML, CSS, JS, Tailwind, React, Next.js and much much more! 👀 ⭐️

Let’s discuss algorithms complexity, and in particular how we measure it in the context of algorithms.

Different algorithms, given the same problem to solve and the same inputs, take a different time to solve the problem.

Sometimes, a hugely different time, especially as the number of elements they need to manage grows.

This complexity is called Big O, for no other reason that we use an upper case o letter as a convention: O(n), O(1) and so on.

The most popular measures of Big O you will see, sorted by more efficient to less efficient, are:

  • O(1)
  • O(log n)
  • O(n)
  • O(n * log n)
  • O(n^2)
  • O(n!)

where n is the number of inputs. For example, if you need to sort 2 items n is 2, and if you need to sort 20.000 items, n is 20.000.

But you don’t need to substitute the value in the O() calculation. That is a symbol, meant to signal developers and everyone looking at the algorithms its efficiency.

An algorithm with O(1) efficiency is the best possible one we can find. The time to execute does not depend on the number of inputs, it always takes the same time to execute

An algorithm with O(n) scales linearly with the number of inputs. If with 10 items it takes 1 second, with 100 items it will take 10 seconds.

An algorithm with O(n^2), if with 4 items takes 16 seconds, with 10 items takes 100 seconds.

We will analyze and calculate the Big O efficiency of a good number of algorithms in the next lessons.

It’s important to note that Big O notation does not give us all the information we need to judge whether an algorithm will be faster than another, in particular if their Big O value is the same. In this case, you will need to use other tools to test the efficiency.

But when algorithms have different classes (O(n) vs O(n^2) for example), there’s no doubt.

One more thing! ⚠️ ✋

At the end of January I will organize the Web Development Bootcamp.

It's a 10-weeks long cohort online course where I will guide you to becoming a Web Developer.

It's not "just a course". It's a big event I organize once a year.

We'll start from zero, learn the fundamentals of Web Development, HTML CSS, JavaScript, Tailwind, Git, using the command line, VS Code, GitHub, Node.js, we'll then learn React, JSX, how to use PostgreSQL, Astro, Next.js, Prisma, deploying on Netlify/DigitalOcean/Fly/Vercel and much more! 

At the end of the first 10 weeks you'll know how to create web sites and web applications and I'll unlock you the 2nd phase of the Bootcamp: you will get access to a large number of projects exclusive to the Bootcamp graduates, so you can follow my instructions to build things like private areas with authentication, clones of popular sites like Twitter YouTube Reddit, create e-commerce sites, and much much more.

Because once you got the fundamentals, you only learn by working on real, exciting projects.

To find out more, visit