Big O notation is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity. In computer science, it's used to classify algorithms according to how their run time or space requirements grow as the input size (n) grows. It describes the **worst-case scenario** and provides an upper bound on the growth rate.
Common Complexities
Notation
Name
Example
O(1)
Constant
Accessing an array element by index.
O(log n)
Logarithmic
Binary Search in a sorted array.
O(n)
Linear
Finding an item in an unsorted list (Linear Search).
O(n log n)
Log-Linear
Efficient sorting algorithms like Merge Sort.
O(n²)
Quadratic
Simple sorting algorithms like Bubble Sort.
O(2ⁿ)
Exponential
Recursive calculation of Fibonacci numbers.
O(n!)
Factorial
Solving the Traveling Salesman Problem via brute-force.