Big O notation

Today I will discuss an important topic that is useful to know for your program but also more importantly it is useful to know for your job interview. According to Wikipedia big-o notation in computer science is used to classify algorithms according to how their run time or space requirements grow as the input size grows. It is essentially how you will talk about and explain your algorithms and how efficient they are as they grow with time “time complexity”. For example how much an algorithm will slow down if you gave it a list of 10 versus a list of 10000. Below I will talk about the common types of big-o notation and exampls.

Constant time “O(1)”

Linear Time “O(n)”

Quadratic Time “O(n²)”

As we look at this example, we see in the function we have two nested loops that increment after each iteration. If we call the function on smallList our n will be 16 operations. We can see how quickly that can add up so imagine what n will be on the function bigList or something even bigger. An array with only one thousand elements ends up creating one million operations, so that gives you an idea.

Logarithmic Time”O(log n)”

Just to give you an idea of how fast logarathmic big-o is if we have a n size of one million we will only return 2 operations thats a big difference from the quadratic big-o.


So at the end of the day you see how important big-o can be, do you nessicaraly need it ot be able to code your project at first no. But if you want to refactor or make it scalable and design someting great from scratch you can see that knowing the big-o can be a very useful tool and help make your app run quicker and smoother.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store