Time Complexity
This section covers the time complexity of algorithms and how it affects the performance of a program.
Definition
Time complexity measures how the runtime of an algorithm changes as the size of the input grows. It is crucial for evaluating the efficiency of algorithms.
Big O Notation (O)
- Describes the upper bound of an algorithm's time complexity.
- Represents the worst-case scenario.
- Example: Binary Search has a time complexity of O(log n).
Big Ω Notation (Ω)
- Describes the lower bound of an algorithm's time complexity.
- Represents the best-case scenario.
- Example: Linear Search has a time complexity of Ω(1) in the best case.
Big Θ Notation (Θ)
- Describes the tight bound, providing both upper and lower bounds.
- Represents the average case or a guarantee of behavior.
- Example: Bubble Sort has a time complexity of Θ(n²).
Common Time Complexities
- O(1): Constant time
- O(log n): Logarithmic time
- O(n): Linear time
- O(n log n): Log-linear time
- O(n²): Quadratic time