Common Big-O Complexities
Big O notation categorizes algorithms based on their growth rates. Here are the most common types, ordered from fastest (most efficient) to slowest (least efficient):
-
O(1) - Constant Time
- Execution time doesn’t depend on input size.
- Example: Accessing an array element by index.
- Graph: Flat line (no growth).
-
O(log n) - Logarithmic Time
- Time grows logarithmically with input size.
- Example: Binary search.
- Graph: Very slow growth, flattens out.
-
O(n) - Linear Time
- Time grows linearly with input size.
- Example: Linear search through an array.
- Graph: Straight line.
-
O(n log n) - Linearithmic Time
- Time grows as ( n ) times the logarithm of ( n ).
- Example: Efficient sorting algorithms like Merge Sort or Quick Sort.
- Graph: Slightly steeper than linear.
-
O(n²) - Quadratic Time
- Time grows quadratically with input size.
- Example: Nested loops, like in Bubble Sort.
- Graph: Parabolic curve.
-
O(n³) - Cubic Time
- Time grows cubically with input size.
- Example: Matrix multiplication with three nested loops.
- Graph: Steep parabolic curve.
-
O(2ⁿ) - Exponential Time
- Time doubles with each additional input.
- Example: Solving the traveling salesman problem via brute force.
- Graph: Extremely steep, quickly becomes impractical.
-
O(n!) - Factorial Time
- Time grows factorially, extremely inefficient for large ( n ).
- Example: Generating all permutations of a set.
- Graph: Explosive growth, worst-case scenario.
📊 Frequently Used Big-O Complexities
| Notation | Name | Example Algorithm |
|---|---|---|
| O(1) | Constant | Accessing an array element |
| O(log n) | Logarithmic | Binary search |
| O(n) | Linear | Iterating through a list |
| O(n log n) | Log-linear | Merge sort, Quick sort (average) |
| O(n²) | Quadratic | Bubble sort |
| O(2ⁿ) | Exponential | Recursive Fibonacci |
🔍 Related Notations
While Big-O describes the upper bound of growth rate:
- Big Theta (Θ) → Tight bound (exact growth rate).
- Big Omega (Ω) → Lower bound (best-case or minimum growth).
These are less commonly used in casual discussions but provide more precise performance characterizations.
💡 Practical Use
- Algorithm Selection: Big-O helps developers pick algorithms that scale well with large datasets.
- Space Complexity: Big-O also applies to memory usage, not just time.
- Focus on Trends: Ignore constants and small terms — large input size behavior is what matters most.
▶ Next: What is Complexity?