Big Oh Notation - formal definition
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Big Oh Notation, also known as Big O notation, is a mathematical notation used to describe the upper bound of the time complexity (or space complexity) of an algorithm. It is a crucial concept in computer science for analyzing and comparing the efficiency of algorithms. Here, we'll delve into its formal definition and practical significance.
Formal Definition
Big Oh Notation is formally defined in terms of functions. Suppose $ T(n) $ and $ f(n) $ are functions where typically represents the size of the input. We say:
if there exist positive constants $ c $ and $ n_0 $ such that:
for all .
This definition essentially means that for sufficiently large input sizes, the growth of is bounded above by a constant factor of .
Technical Explanation and Examples
Example 1: Linear Time Complexity
Consider a simple algorithm that calculates the sum of elements in an array of size . The time complexity of this algorithm can be expressed as , where $ c $ and $ d $ are constants representing the time to process each element and the setup overhead, respectively.
To express this in Big O notation, observe that for large , the term dominates the behavior of . So, we can say:
Example 2: Quadratic Time Complexity
Consider a nested loop algorithm where for every element of the input, we perform a linear scan. This results in a time complexity of .
Applying the definition of Big Oh, we find:
because the quadratic term dominates as grows larger.
Example 3: Logarithmic vs. Linearithmic Complexity
Algorithms like binary search operate in logarithmic time, formally written as , while sorting algorithms like Merge Sort operate in . Here are examples of relevant functions and their Big O notation:
- Binary Search:
- Merge Sort:
Key Properties of Big Oh Notation
- Transitivity: If
$ f(n) = O(g(n))$ and $g(n) = O(h(n)) $, then . - Additivity: If
$ f(n) = O(h(n))$ and $g(n) = O(h(n)) $, then . - Multiplicativity: If , then for any constant .
Common Big O Notations
Below is a table summarizing common Big O notations and their characteristics:
| Complexity Class | Notation | Example Algorithms | Characteristics |
| Constant Time | Indexing an array | Time does not vary with input size | |
| Logarithmic Time | Binary Search | Decreases significantly with larger inputs | |
| Linear Time | Simple loop over list | Grows directly in proportion to the input size | |
| Linearithmic | Merge Sort | Combines linear and logarithmic growth factors | |
| Quadratic Time | Bubble Sort | Growth rapidly increases with input size | |
| Cubic Time | Matrix Multiplication (naive) | Growth becomes unsustainable at larger scales | |
| Exponential Time | $ O(2^n) $ | Recursive Fibonacci Calculation | Grows unmanageably with even small increases in $ n $ |
| Factorial Time | $ O(n!) $ | Traveling Salesman Problem | Grows extremely fast, often intractable for large $ n $ |
Conclusion
Big Oh Notation provides a high-level understanding of the algorithm's complexity. However, it focuses on the upper bound, ignoring constant factors and lower-order terms. In practice, it's crucial to consider these factors for a complete performance analysis. By helping to abstract the behavior of algorithms, Big Oh Notation remains a powerful tool for computer scientists and engineers in algorithm design and analysis.

