The ‘Big O’ Champion – Part 1

·

3 min read

Have you heard about the most interesting topic of Data Structures and Algorithms? It’s not only one of the most complex topics but also often asked by the grill cooks during coding interviews. Can you take a guess? I mean of course, from the title, you must have got a hint. It’s the Big O!

When I first learned about Big O and its complexities, my mind was blown away. It was so difficult to get the hang of all the graphs and the concepts that came along with it. Nobody that I knew of could help me either. So, after burning a ton of midnight oil, I finally unraveled the Big O mystery and decided to share the hidden pulse with everyone. So here comes a five-part series starting with, of course, hors d’oeuvre. Hope you are all feeling hungry!

Whether you are a newbie who has just dipped his toes in the deep waters of DSA or a little confused soul, there is no need to worry cause I’m there for you. I’ll break down the barrier for you and lay out a simple path. So, let’s start this exciting journey of becoming the ‘Big O’ Champion!!!

In this blog, I’ll be talking about:

  1. What is Big O?

  2. The Case of Big O.

What is Big O?

Big O is a way of comparing two sets of code based on efficiency. For example, there are two code sets, Code 1 and Code 2. Code 1 is easy to read but Code 2 on the other hand is concise. So Big O will calculate mathematically and decide which one is more efficient.

Big O considers two types of complexities for its calculations:

  • Time Complexity: Let’s say you have a stopwatch. You run Code 1 and it takes 15secs to complete its execution whereas Code 2 takes up an entire minute to finish running. By this test, Code 1 is declared efficient. This is Time Complexity.

    However, if we run the same code sets on a different device, it may give us a different time analysis. That’s why, Time complexity is measured by the number of operations a code takes to complete something.

  • Space Complexity: Code 1 (that ran faster) occupies a huge amount of space. Meanwhile, Code 2 is happy with a small area. Now if we go by this analysis, Code 2 will be declared as efficient provided execution time is not our priority. This is Space Complexity.

The Case of Big O.

While dealing with Time and Space complexities, we come across 3 Greek letters i.e., Omega (Ω), Theta (θ) and Omicron (O). Yes! You saw it right! Our Big O uses the Omicron symbol.

Now what is this case with Big O? Let me explain this through an example:

I have drawn an array of 1-7 digits as you can see below.

If we have to use 'for loop' and search for 1, it will be our Best case represented by Omega (Ω). Similarly, for 4, it will be our Average case represented by Theta (θ). And lastly, if we search for 7, it will be our Worst case represented by Omicron (O).

So, as you might have guessed by now, Big O represents the Worst Case.

I guess now, you have got a taste of it. Drop a ❤️ if you have loved the first course. But wait! We have just started and the appetizer is yet to follow. Till then…

Learn, Share, Grow!

Bye!