Big O Notation
Big O notation is a mathematical notation used in computer science to describe how an algorithm's running time or memory usage grows as the size of its input increases, focusing on worst-case or upper-bound growth rate rather than exact…
Definition
Big O notation is a mathematical notation used in computer science to describe how an algorithm's running time or memory usage grows as the size of its input increases, focusing on worst-case or upper-bound growth rate rather than exact timing.
Overview
Big O abstracts away hardware speed, constant factors, and implementation details to answer a specific question: as input size n grows very large, how does the algorithm's resource usage scale? Common classes include O(1) constant time, O(log n) logarithmic (as in binary search), O(n) linear, O(n log n) (as in efficient sorting algorithms like mergesort), O(n²) quadratic (as in simple nested-loop algorithms), and O(2^n) exponential — each describing a fundamentally different growth curve as inputs scale, which becomes the dominant factor in performance for sufficiently large inputs regardless of constant-factor optimizations. Big O is central to comparing data structures and algorithms: choosing a hash table over a linked list for lookups, for example, is fundamentally a Big O decision — O(1) average-case lookup versus O(n) linear search. It's also essential for reasoning about recursion's cost, since many recursive algorithms' complexity is derived from a recurrence relation describing how the problem shrinks with each call. Big O describes asymptotic, worst-case (or sometimes average-case) behavior, not actual wall-clock speed for any specific input size — an O(n²) algorithm can outperform an O(n log n) one on small inputs due to lower constant overhead. Related notations, Big Omega (best case) and Big Theta (tight bound), are less commonly used in everyday practice, but Big O itself is a standard part of technical interviews and a foundational tool for reasoning about algorithm scalability.
Key Concepts
- Describes how running time/memory scales with input size
- Focuses on asymptotic, worst-case growth rather than exact timing
- Common classes: O(1), O(log n), O(n), O(n log n), O(n²), O(2^n)
- Ignores constant factors and hardware-specific speed differences
- Essential for comparing algorithms and data structures
- Standard framework used in technical coding interviews
Use Cases
Frequently Asked Questions
From the Blog
Big-O Notation Explained: Time & Space Complexity
Understand Big-O notation, time and space complexity, and the common growth rates with clear worked examples so you can reason about performance and ace interviews.
Read More ProgrammingWhat Is Big O Notation? A Beginner Guide
Big O notation describes how an algorithm's time or memory grows as input size increases. Learn the common complexities and how to analyze your own code.
Read More Cloud & CybersecurityWhat Is a Subnet Mask? Subnetting Explained Simply
A subnet mask tells a device which part of an IP address identifies the network and which part identifies the specific host on it. This guide explains subnet masks, subnetting, and how to read CIDR notation.
Read More