What are the various asymptotic notations?
1. Meaning of complexity: Complexity measures how the resource use of an algorithm grows as the input size grows. Time complexity counts elementary operations (comparisons, assignments, arithmetic) as a function of ; space complexity counts memory cells used. Auxiliary space is the extra space beyond the input. We study worst case (maximum over inputs of size n), average case (expected) and best case (minimum), and use asymptotic estimates so that constants and small inputs do not hide the growth trend.
2. Formal asymptotic definitions (f, g nonnegative):
- Big Oh: iff there exist and such that for every . The function is an eventual upper bound.
- Omega: iff there exist and such that for every . The function is an eventual lower bound.
- Theta: iff there exist , and such that for every ; that is, intersect , a tight bound.
- Strict forms: when ; when .
3. Common growth-rate order (slowest to fastest): . Examples: array access ; binary search ; linear search ; merge sort ; triple matrix loop ; subset enumeration ; all permutations .
4. Suitable qualitative growth diagram:
Operations / time T(n)
^
| n!
| _.-'
| _.-' 2^n
| _.-'
| _.-' n^3
| _.-' n^2
| _____/ n log n
| ___/ n
| ___/ log n
|___/__________________________________________> input size n
The x-axis is input size and the y-axis is operations / running time . The curves lie close for small but separate for large , which is why constant factors are ignored. A Θ bound places between two multiples of beyond :
T(n)
^ . . . . . . c2*g(n) upper bound
| . f(n)
| . /
| . . . . . . . . c1*g(n) lower bound
+---------------------------> n
5. Application to the asked question: For with : for , so ; also , so ; hence . Binary search is , linear search and merge sort ; the growth-rate order tells us which stays faster as increases.
Measuring an algorithm without counting seconds. Complexity analysis estimates how the running time or memory requirement of an algorithm grows with the size of its input, independent of machine speed and programming language. Time complexity counts the number of basic operations as a function of input size, while space complexity counts the memory used. Asymptotic notation describes the dominant term and ignores constant factors and lower order terms. Big O gives an upper bound: a function is O of g if it is at most a constant multiple of g for all sufficiently large inputs. Omega gives a lower bound and Theta gives a tight bound, meaning both an upper and a lower bound with possibly different constants. Common growth rates in increasing order are constant, logarithmic, linear, linearithmic, quadratic, cubic and exponential. A suitable diagram shows horizontal bands for the bounding functions and the algorithm curve staying within them beyond some input size. The time space tradeoff is the design choice in which extra memory is used to reduce running time, as when a hash table gives fast lookup at the cost of storage or when memoisation stores computed results to avoid recomputation. Worst case complexity bounds the behaviour on the most difficult input of a given size, average case is the expectation over a distribution and best case concerns the easiest input. A good answer defines complexity and each notation with inequalities, draws or describes the growth diagram, lists common orders and explains the time space tradeoff with a concrete example. Noting that constants matter in practice even though asymptotic notation ignores them shows a balanced understanding.
Result: Complexity is the growth of time/space with ; O, Ω and Θ bound it above, below and tightly, and the diagram shows the standard growth-rate ladder.
Key Points
- Complexity T(n)/S(n) measures time/memory as a function of input size n
- Worst, average and best case; auxiliary space is extra space
- O: 0 <= f(n) <= c g(n) for n >= n0 (upper bound)
- Ω: 0 <= c g(n) <= f(n) for n >= n0 (lower bound)
- Θ: c1 g(n) <= f(n) <= c2 g(n) for n >= n0 (tight bound)
- Growth order: 1 < log n < n < n log n < n^2 < n^3 < 2^n < n!
- Diagram axes: x = input size n, y = operations T(n); curves diverge for large n
- Example: 3n+5 is Θ(n); binary search Θ(log n); merge sort Θ(n log n)