Algorithm Complexity
1. What is Algorithm Complexity?
Algorithm complexity measures the efficiency of an algorithm in terms of:
Time Complexity – Number of steps executed by an algorithm.
Memory Complexity – Amount of memory used during execution.
Factors Affecting Algorithm Running Time:
Input size and type.
Efficiency of the compiler.
Speed of the executing machine.
Complexity of the algorithm itself.
2. Measuring Efficiency of Algorithms
Efficiency is categorized based on how execution time increases with input size nn.
Basic Complexity Categories:
3. Understanding Big-O Notation
Big-O notation describes the upper bound (worst-case scenario) of an algorithm’s complexity.
Rules for Determining Big-O:
Keep the dominant term (largest term in the function).
Ignore coefficients (constants don’t affect complexity ranking).
Rank of common complexities (from best to worst performance):
O(1)O(1) → O(logn)O(\log n) → O(n)O(n) → O(nlogn)O(n \log n) → O(n2)O(n^2) → O(n3)O(n^3) → O(2n)O(2^n) → O(n!)O(n!)