Introduction to Asymptotic Analysis and Big (O)
Explore the core concepts of asymptotic analysis and Big O notation to understand how to compare algorithm complexities for large input sizes. This lesson helps you simplify and apply Big O notation, enabling you to evaluate and optimize algorithm performance in Java coding interviews.
We'll cover the following...
We have seen that the time complexity of an algorithm can be expressed as a polynomial. To compare two algorithms, we can compare the respective polynomials. However, the analysis performed in the previous lessons is a bit cumbersome and would become intractable for bigger algorithms that we tend to encounter in practice.
Asymptotic analysis
If the input size is really small, how bad can a poorly designed algorithm get, right? Therefore, mathematicians have a tool for this sort of analysis called the asymptotic notation. The asymptotic notation compares two functions say, and for very large values of . This fits in nicely with our need for comparing algorithms for very large input sizes.
Big (O) notation
One of the asymptotic notations is the Big O notation. A function is considered (read as big oh of ) if there exists some positive real constant and an integer , such that the following inequality holds for all :
The following graph shows a plot of a function and that demonstrates this inequality.
Note that the above inequality does not have to hold for all values of . For , is allowed to exceed , but for all values of beyond some value , is not allowed to exceed .
What good is this? It tells us that for very large values of , will be at most within a constant factor of ...