Skip to main content
CSAlgorithms & ComplexityDiagramBeginner

Big-O Notation

KO: 빅오 표기법·EN: Big-O Notation·JA: ビッグオー記法

An asymptotic notation describing how an algorithm's worst-case runtime or memory grows as input size N scales

Table of Contents

Structure Diagram

Big-O Time Complexity Growth Curves
Rapid BottleneckBinary SearchInput Size (N) →Operat
(50, 6)O(1) Constant #3
Quick Answer

What is Big-O Notation?

An asymptotic notation describing how an algorithm's worst-case runtime or memory grows as input size N scales. It is a core concept in Algorithms & Complexity within CS.

Core Principles

Big-O Notation provides a hardware- and language-independent way to measure how an algorithm scales as input size N grows. By dropping constant multipliers and lower-order terms (so 3N² + 20N + 5 simplifies to O(N²)), it isolates the dominant growth curve under worst-case conditions.

From fastest to slowest, common complexity tiers are O(1) (constant) < O(log N) (logarithmic) < O(N) (linear) < O(N log N) (linearithmic) < O(N²) (quadratic) < O(2^N) (exponential). For 50 items the gap is invisible, but at 100,000 items O(N log N) finishes in milliseconds while O(N²) grinds a server to a halt.

Practical Takeaways

  • Flatten hidden nested loops with Hash Maps: Calling .includes() or .find() inside a .map() or for loop quietly creates O(N×M) behavior. Pre-indexing lookups into a Set or Map cuts total work to O(N+M).
  • Leverage time-space tradeoffs: Caching, memoization, and database indexes trade extra O(N) memory to collapse repeated O(N) or O(N²) scans into O(1) or O(log N).
  • Remember constants for small N: Big-O describes asymptotic growth. For tiny arrays (N < 32), a cache-friendly O(N) linear scan often outperforms a hash map or balanced tree in real wall-clock time.

Notable Examples

  • O(1): Direct array indexing (arr[i]) and hash table lookups.
  • O(log N): Binary search on sorted arrays and B-Tree database index lookups.
  • O(N log N): Production sorting algorithms such as Timsort and Merge Sort.
  • O(N²): Naive all-pairs collision checks—the exact reason game engines use spatial hashing or quadtrees.