To evaluate the efficiency of an algorithm, we analyze its performance using the following measures:
1. Time Complexity
Represents the time taken by an algorithm to run as a function of input size (n).
Expressed using Big-O notation (O).
Examples:
O(1) - Constant time
O(log n) - Logarithmic time (Binary Search)
O(n) - Linear time (Linear Search)
O(n log n) - Log-linear time (Merge Sort)
O(n²) - Quadratic time (Bubble Sort)
2. Space Complexity
Represents the memory required by an algorithm.
Important for optimizing performance in memory-constrained environments.
3. Best, Average, and Worst Case Analysis
Best Case: Minimum time required (ideal scenario)
Average Case: Expected performance over different inputs
Worst Case: Maximum time required (upper bound)
Comments
Post a Comment