Asymptotic Notation
Asymptotic notations are mathematical tools to represent time complexity of algorithms.
Asymptotic notations are used to write fastest and slowest possible running time for an algorithm. These notations are important because without expanding the cost of running the algorithm, we can estimate the complexity of the algorithm.
Asymptotic notations is a way of comparing functions that ignores constant factors and small input size.
Big Oh Notation(O)
The notation O(n) is the formal way to express the upper bound of an algorithm’s running time. It measures the worst case time complexity or the longest amount of time an algorithm can possibly take to complete.
Example - Insertion Sort
f(n) = O(g(n)) If and only if exist positive constant C
f(n) <= k.g(n) for n>n0 in all cases.
Omega Notation(Ω)
The notation Ω(n) is the formal way to express the lower bound of an algorithm’s running time. It measures the best case time complexity or the best amount of time an algorithm can possibly take to complete.
f(n) = Ω(g(n)) if and only if there exists positive constant c and n0.
f(n) >= k(g(n))for all n, n >= n0.
Theta Notation (θ)
The notation θ(n) is the formal way to express both the lower bound and the upper bound of an algorithm’s running time.
f(n) = θ(g(n)) If and only if there exists positive constant k1,k2 and k0 such that
K1 g(n) <= f(n) < k2 g(n) for all n, n >= n0.
Comments
Post a Comment