Time Complexity
Asymptotic Notations
Big oh - O - Upper bound - f(n)=O(g(n)) iff f(n)≤c⋅g(n) - Any higher/equal order function than average case
Big omega - Ω - Lower bound - f(n)=Ω(g(n)) iff f(n)≥c⋅g(n) - Any lower/equal order function than average case
Theta - θ - Average bound - f(n)=θ(g(n)) iff c1⋅g(n)≤f(n)≤c2⋅g(n)
Since θ gives most accurate bound of a function, it is preferred over O and Ω which are boundless.
Note: These aren't linked with best case or worst case scenarios, these are just notations. Worst case and best case can be shown using any of these notations.



Properties
Reflexive
Transitive
Symmetric
Transpose Symmetric
Transpose Symmetric is if f(n)=O(g(n)) then g(n)=Ω(f(n))
Comparing Functions
Functions can be directly compared, however, two functions can be of same complexity (asymptotically equal) even if their constants are unequal. Natively constants do not hold significance in comparing functions.
If two functions cannot be directly compared (i.e. powers exist), logarithms can be used to compare such functions, however, when taking logarithm - any constants generated by application of logarithm DO HOLD significance and hence after application of logarithm, two functions cannot be asymptotically equal if they have differing constant coefficients.
Examples
Functions 2nn and 3nn are asymptotically equal.
Functions 22nn and 23nn are NOT asymptotically equal, even though on application of logarithm it produces the same functions as in Example 1.
Big O Cheat Sheet

Calculating complexity
1 sec = 108 operations (approx.)
Example
Time constraint: 20 seconds
0<n≤2×105
Here to find out the time complexity, consider n2=4×1010 which would equal to 400 seconds. Hence, time complexity here should be less than O(n2).
Last updated