- Published on
Behind The Algorithm #5 - 🧘🏻 Asymtotic Notation
- Authors
- Name
- Galih Laras Prakoso
- @galihlprakoso
Asymptotic Efficiency
When the input size is large enough, sometimes the most impactful or the only impactful part of a function is the order of growth. The multiplicative constants and the lower-order terms will not giving so much impact to the growth of the running time.
Asymptotic efficiency is when we're trying to optimize our algorithm by focusing on the optimization of the order of growth.
In other words, we're trying to optimize our algorithm by focusing to decrease the running time by looking at the limit defined by the notation that defined the worst-case of the function while the input increases without bound. Usually, we can compare algorithms or justify which algorithm is better by looking at their asymptotic efficiency.
Asymptotic Notation
Just to recall, do you remember when we calculated the running time of the insertion sort in the previous article? We know that the insertion sort is having running time right? And we also calculated the running time of the merge sort so we know that it's running time is .
As you can see that we ignored the lower-order terms. Because sometimes, forcing to include the extra precision is not usually worth the effort for large enough inputs.
To make it more clear, the quadratic running time of the insertion sort where . When is large, even just a tiny fraction of the highest-order term would dominate every single lower-order terms. So, wehen we throw away the lower-order terms and ignore all of the constants we get .
In other way, we can set the constants , , and . You may also verify that for all .
We abstracted the running time of the insertion sort which is by writing it as . That's how we characterize the worst-case running time of insertion sort.
Asymptotic Upper Bound or the Big O notation
The worst-case running time of the insertion sort is . Let see what's the meaning of this notation by looking at this graph first.
We use the Big O notation to give as the upper bound on a function to within a constant factor. As you can see in the image above that the function is always bellow the which is the upper bound of the running time of the function for all values of is bigger (to the right) or equal to .
Let's just write the function as . It means that the is a member of set . In other words, in our insertion sort case, , where .