โ Asymptotic Notations
โ 1. Introduction
Asymptotic Notations are mathematical tools used to describe the time complexity and space complexity of an algorithm when the input size n becomes very large.
โ They help us to:
- Measure algorithm performance
- Compare two algorithms
- Ignore constants and less important terms
- Focus on growth rate of algorithm
๐ Example:
If an algorithm takes 5n + 10 operations, for large n, the main term is n.
So complexity becomes O(n).
โ 2. Why Asymptotic Notations are Needed?
As input size increases, the execution time changes.
Asymptotic notations help us to calculate how fast the algorithm grows.
โ Benefits:
- Independent of machine speed
- Independent of programming language
- Easy comparison of algorithms
- Useful for large data problems
โ 3. Types of Asymptotic Notations
The main asymptotic notations are:
- โ Big-O Notation (O) โ Worst Case
- โ Big-ฮฉ Notation (ฮฉ) โ Best Case
- โ Big-ฮ Notation (ฮ) โ Average / Exact Case
(Other notations also exist like little-o and little-ฯ, but these 3 are most important for BCA.)
โ 4. Big-O Notation (O) โ Worst Case
โ Definition
Big-O notation represents the upper bound of an algorithm.
It tells the maximum time an algorithm may take in the worst situation.
๐ Meaning:
Even in the worst case, algorithm will not take more time than O(f(n)).
โ
Example:
Linear Search in array:
- Best case: element found at first index โ O(1)
- Worst case: element found at last or not found โ O(n) โ
๐ Example function:T(n) = 3n + 5
In Big-O:
๐ O(n) (ignore constants)
โ Common Big-O examples:
- O(1) โ constant time
- O(n) โ linear time
- O(nยฒ) โ quadratic time
โ 5. Big-ฮฉ Notation (ฮฉ) โ Best Case
โ Definition
Big-ฮฉ notation represents the lower bound of an algorithm.
It tells the minimum time required by an algorithm in the best case.
โ
Example:
Linear Search:
- Best case: element found at first position โ ฮฉ(1) โ
๐ Example function:T(n) = 3n + 5
In Big-ฮฉ:
๐ ฮฉ(n)
โ Best case helps to know minimum time when conditions are favorable.
โ 6. Big-ฮ Notation (ฮ) โ Average / Tight Bound
โ Definition
Big-ฮ notation represents the tight bound of an algorithm.
It tells the exact or average growth rate of the algorithm.
๐ Big-ฮ is used when both upper and lower bounds are the same.
โ
Example:
If algorithm always takes n steps:
- Upper bound = O(n)
- Lower bound = ฮฉ(n)
So,
โ Tight bound = ฮ(n)
๐ Example function:T(n) = 4n + 20
Big-ฮ:
๐ ฮ(n)
โ 7. Summary Table (Very Important for Exam)
| Notation | Name | Represents | Meaning |
|---|---|---|---|
| O(f(n)) | Big-O | Upper Bound | Worst case time |
| ฮฉ(f(n)) | Big-Omega | Lower Bound | Best case time |
| ฮ(f(n)) | Big-Theta | Tight Bound | Average / exact time |
โ 8. Simple Example (For Better Understanding)
โ Example: Linear Search
Search an element in array of size n
- Best Case: element found at first position
โ Time = ฮฉ(1) - Worst Case: element found at last / not found
โ Time = O(n) - Average Case: found somewhere in middle
โ Time = ฮ(n)
โ 9. Important Note (How We Simplify Functions)
While calculating asymptotic complexity:
โ Ignore:
- Constants
- Lower order terms
Example:T(n) = 6nยฒ + 3n + 10
For large n, the highest power dominates:
โ
Complexity = O(nยฒ)
โ Conclusion
Asymptotic notations are used to describe the performance of algorithms in terms of time and space for large input size. The most commonly used notations are Big-O (worst case), Big-ฮฉ (best case) and Big-ฮ (average or tight bound).
