Time Complexity and Asymptotic Notation
Why we need Asymptotic Notation
In most of the time, we don't need to calculate the exact computational time for a given algorithm. For an input that is large enough, the coefficient on the lowest term will have little effect on the overall computational time for the whole algorithm. Therefore, the main trend of computational time is determined by the highest term of the polynomial.
When we are focusing on how the computational time increases as the scale of input increase, we are calculating the Asymptotic Efficiency of algorithm.
What we do concern is how the running time of algorithm increase as the scale of input increase. In this case, we need to employ the asymptotic notation to help us analyze the time complexity of algorithm.
| Big-Theta Notation
This notation represents a set of functions that has a tight upper bound and lower bound. If a function is in the set , then we know that there exists , , and such that
| Big-O Notation
This notation represents a set of functions that has a specific upper bound. If a function is in the set , then we know that there exists a and such that
Since the big O notation only specify the upper bound of function, it is a much bigger set than big theta notation. Which means that .
| Big-Omega Notation
This notation represents a set of functions that has a lower bound. For all function in the set , it must satisfy that there exist and such that
Amortized Analysis of Time Complexity
The Amortized Analysis of Time Complexity is the calculation of average time complexity of an operation.
Example: In Java, the arrayList
item is in fact a array
. When it is full, it will copy the elements from original array into a new array with length 1.5 times the original one.
Though it seems to be inefficient and may have a time complexity of for some situation, the Average time complexity of adding an item into the arrayList
is still .
Suppose reading & writing one element in an array will take time of . Constructing an array of length will take:
Therefore, on average, the time it takes to add one element in the array will be .