Here we are mainly going to focus on calculating the Time Complexity which generally depends on the size of the input. Let's understand this point with the help of an example.
Suppose we have an integer array and we want to add an element at the beginning of the list then to perform this operation we need one extra space at the end of the array and we have to shift all the elements of the array by one unit and the number of the shift we have made is equal to the number of elements present in the given array.
So from this small example, we can understand that Running Time mostly depends on the size of the input. Therefore, if the size of the input is n, then f(n) is a function of n that denotes the Time Complexity. Example:
| n | 5n^2 | 6n | 12 |
|---|---|---|---|
| 1 | 21.74% | 26.09% | 52.17% |
| 10 | 87.41% | 10.49% | 2.09% |
| 100 | 98.79% | 1.19% | 0.02% |
| 1000 | 99.88% | 0.12% | 0.002% |
Now if we observe the above table we found that for a bigger n value 5n^2 it takes most of the time so while calculating the Time Complexity we can neglect the remaining terms because the single term gives us the approximate result and it is very near to the actual result. This approximate measure of time complexity is called Asymptotic Complexity.
What are Asymptotic Notations?
O(n) Big O notation. (Worst Case)
We have to find out another function in such a way that the function is greater than the given f(n), let's call it c.g(n), after some limit n=no
Example: Is f(n) is big O of g(n) [f(n) = O(g(n))] where f(n) = 3n+2 and g(n) = n.
Solution: At first we have to find two constants c and no such that,
f(n)<=c.g(n), c > 0 and n >=no
Ω(n) Omega notation. (Best Case)
Now after finding out that, if we can bound that function by some another function say c.g(n) in such a way that after some input no, the value of c.g(n) is always smaller than f(n).
[ f(n)>=c.g(n) ], after some n where is n>=no
c, n are real numbers, c > 0 and n >=no
Definition: f (n) ∈ Ω(g(n)) if there exists constants c > 0 and n0 >= 1 such that 0 ≤ c ·g(n) ≤ f (n) for all n ≥ n0
Solution:
Θ(n) Theta notation. (Average Case)
If f(n) is bounded by c1g(n) and c2g(n) then, f(n) is Θg(n).
Definition: f (n) ∈ Θ(g(n)) if there exists constants c1 > 0, c2 > 0 and n0 > 1 such that c1 ·g(n) ≤ f (n) ≤ c2 ·g(n) for all n ≥ n0
Example: Is f(n) is big Theta of g(n) where f(n) = 3n+2 and g(n) = n.
👉Support Us by Sharing our post with others if you really found this useful and also share your valuable feedback in the comment section below so we can work on them and provide you best 😊.(alert-success)




No comments
Post a Comment