As developers, we write new algorithms or work on existing ones. And whenever we code something we should ask ourselves multiple questions. One of these questions is:
How efficient is my code?
One key element when writing algorithms are data structures and each data structure has its own pros and cons. In this blog article, my goal is to give you an introduction to Big O Notation, why it's very important even when it's not that crucial for your daily job.
Big O Notation in a nutshell: How the algorithm is performing and how well it scales.
You can divide this into 2 forms:
How much time is needed until my algorithm is finished.
How much space it needs in the RAM.
This really matters when you want to scale your application. Imagine the massive data Google has to process every day.
If you are a Google Engineer Big O should sound very familiar.
The notation is the way we can define a algorithm.
There are much more but just to give you some examples. These simple terms define the efficiency of an algorithm. O(1) for examples means that the code always needs the same time. Its constant.
O(n) is different. n is a variable and defines the input. Imagine you have a for loop and iterate n times where n is for example a user input. The user can always change his/her input. Its not constant.
Here is a nice cheat sheet for Big O Notation.
Let's be honest. Many of you don't know or don't care about Big O Notation that much. And most of you don't have to. Even i don't give it that much value when writing code most of the time.
First of all, we have to focus to find a solution to a certain problem before we work on efficiency.
But there are use cases where this is a huge factor.
As mentioned above if you or your company have to deal with massive amounts of data Big O Notation is crucial. The exact same problem can be solved in 100 ways. 1 of these ways is efficient in terms of Big O and needs 3 seconds. The 99 others need longer, sometimes 1000x more. And the difference between 3 seconds and 3000 seconds is a game-changer.
If you don't work with a lot of data you don't have to worry about efficiency that much. I really enjoy thinking about different ways to solve one problem and always try to be as efficient as possible. And with that mindset, you can work on your Big O skills without being forced to do it. Who knows, maybe one day you will need it and then you are happy you can do it.
Also, the best benefit is that you can improve as a developer as you learn more algorithms and data structures and how to use them in your day job.
I also wrote about these things like Linked Lists and Merge Sort. You can check it out on my blog posts if you are interested.
Also you can work on your Big O and problem solving skills at the same time at these platforms:
I really hope that i explained it in an easy way and that you learned something new!
Stay connected to me and my content on Twitter.
I love to improve myself every single day even if it's just a tiny bit!
Stay safe and healthy guys!
And as always: develop yourself!