1. Big O Notation – O (Upper Bound)
Big O Notation tells the Worst-Case performance of an algorithm. It is also known as the Upper Bound.
- Meaning: It guarantees that the algorithm’s running time will never go above a certain limit. It shows how slow the algorithm can be in the worst case.
- On Graph:
- If a function f(n) has a time complexity O(g(n)), it means that after a point (n₀), f(n) will always remain below or on the line c · g(n).
- Formula: f(n) ≤ c · g(n) for all n ≥ n₀
- Example: If we say Quick Sort has a Worst-Case complexity of O(n²), it means its growth will not exceed n².
2. Omega Notation – Ω (Lower Bound)
Omega Notation tells the Best-Case performance of an algorithm. It is also called the Lower Bound.
- Meaning: It guarantees that the algorithm’s running time will never go below a certain limit. It represents how fast the algorithm can be.
- On Graph:
- If a function f(n) has a time complexity Ω(g(n)), it means that after a point (n₀), f(n) will always remain above or on the line c · g(n).
- Formula: f(n) ≥ c · g(n) for all n ≥ n₀
- Example: Quick Sort’s Best-Case complexity is Ω(n log n). This means it will not run faster than n log n.
3. Theta Notation – Θ (Tight Bound)
Theta Notation represents the Average-Case or Exact Asymptotic Behavior of an algorithm. It is also known as the Tight Bound.
- Meaning: It is the most precise notation. It guarantees that the algorithm’s running time will lie between two functions (c₁ · g(n) and c₂ · g(n)). This means the growth rate in both best and worst cases is almost the same.
- On Graph:
- If a function f(n) has a time complexity Θ(g(n)), then after a point (n₀), f(n) will always remain between c₁ · g(n) and c₂ · g(n>.
- Formula: c₁ · g(n) ≤ f(n) ≤ c₂ · g(n) for all n ≥ n₀
- Example: Merge Sort always has a complexity of Θ(n log n). This means its running time will always stay around n log n.
Summary
| Notation | Big O (O) | Omega (Ω) | Theta (Θ) |
|---|---|---|---|
| Meaning | Upper Bound | Lower Bound | Tight Bound |
| Case | Worst-Case | Best-Case | Average-Case |
| Simple Meaning | Will never exceed this | Will never go below this | Will stay around this |
These notations help us understand how an algorithm grows or slows down when the input size increases.
Comments
Post a Comment