CSC211 ยท 2079 ยท 5 marks
Why do we need asymptotic notation? Describe about Big oh notation with its curve.
Why do we need asymptotic notation? Describe about Big oh notation with its curve. [5]
Quick answer
When we analyze algorithms, we need a way to measure and compare their efficiency (time and space) without depending on machine speed, programming language, or hardware. Asymptotic notation provides a mathematical framework to describe the behavior of an algorithm as the input size grows toward infinity.
Asymptotic Notation and Big Oh Notation
Why Do We Need Asymptotic Notation? (2 marks)
Key reasons we need asymptotic notation:
- To compare two algorithms independently of machine or implementation details.
- To describe the growth rate of an algorithm's running time or space requirement.
- To focus on the dominant term of a function and ignore constants and lower-order terms, which become insignificant for large inputs.
- To express best case, worst case, and average case complexity in a standard, concise way.
For example, if an algorithm takes T(n) = 5nยฒ + 3n + 10 steps, asymptotic notation lets us simply say it grows as nยฒ, ignoring less significant terms.
Big Oh Notation O(g(n)) (3 marks)
Definition:
"When we have only asymptotic upper bound then we use O notation. If f and g are any two functions from set of integers then function f(x) is said to be big Oh of g(x)."
Formally:
f(n) = O(g(n)) if and only if there exist positive constants c and nโ such that:
$$f(n) \leq c \cdot g(n) \quad \text{for all } n \geq n_0$$
- f(n) is the actual running time of the algorithm.
- g(n) is the bounding function (upper bound).
- c and nโ are positive constants.
This means Big Oh gives the worst-case or upper bound on the growth of an algorithm.
Example
If f(n) = 4n + 2, then:
- 4n + 2 โค 5n for all n โฅ 2
- So f(n) = O(n), with c = 5 and nโ = 2
Curve / Graphical Representation
Running
Time
| c * g(n)
| ./
| ./
| .../ <-- f(n) always stays
| .../ below c*g(n) after nโ
| .../
| .../
|../
|_________________________ n
nโ
- For all values of n โฅ nโ, the curve of f(n) lies at or below the curve of c * g(n).
- Big Oh notation thus represents the asymptotic upper bound.
Key Points
| Property | Description |
|---|---|
| Notation | O(g(n)) |
| Meaning | Upper bound on running time |
| Use case | Worst-case analysis |
| Condition | f(n) โค c * g(n) for all n โฅ nโ |
Common Big Oh Complexities (Best to Worst)
$$O(1) < O(\log n) < O(n) < O(n \log n) < O(n^2) < O(2^n) < O(n!)$$
Conclusion: Big Oh notation is the most widely used asymptotic notation because it tells us the maximum time an algorithm will ever take, helping us guarantee performance in the worst case.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.