A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Algorithm Complexity and Big-O Notation

College Depth 80 in the knowledge graph ☐ I know this ☆ Set as goal
12topics build on this
411prerequisites beneath it
See this on the map →
Algorithm Analysis and Big-O Notation→→Computational Social Science
Big-O time-complexity space-complexity asymptotic-analysis

Core Idea

Big-O notation f(n) = O(g(n)) means f(n) ≤ c·g(n) for large n and some constant c. It abstracts away constants and low-order terms to focus on growth rate. Complexity classes include O(1) (constant), O(log n) (logarithmic), O(n) (linear), O(n²) (quadratic), O(2ⁿ) (exponential).

How It's Best Learned

Analyze simple algorithms (searching, sorting, graph traversal) to derive complexity. Count basic operations: comparisons, assignments, loop iterations. Compare growth: 2ⁿ vastly exceeds nⁿ for large n, yet both are 'hard.' Use recurrence relations for recursive algorithms.

Common Misconceptions

Big-O is an upper bound; Ω is lower bound; Θ is tight. O(n) ≠ O(n²); the first is strictly better. Constants matter in practice even if Big-O ignores them.

Explainer

You already know Big-O from algorithm analysis — O(n) is linear, O(n²) is quadratic, and these labels describe how runtime grows with input size. The discrete math lens formalizes this: Big-O is a mathematical relation between functions, defined precisely as f(n) = O(g(n)) whenever there exist constants c > 0 and n₀ such that f(n) ≤ c·g(n) for all n ≥ n₀. This definition clarifies that Big-O is an *upper bound*, not an exact description — saying an algorithm is O(n²) tells you it doesn't grow faster than quadratic; it might actually be much faster. The definition also explains why constants are dropped: any constant factor can be absorbed into c.

The hierarchy of complexity classes — O(1), O(log n), O(n), O(n log n), O(n²), O(2ⁿ) — describes a spectrum from "nearly free" to "infeasibly slow." Logarithmic growth is nearly constant in practice: log₂(1,000,000) ≈ 20. Linear is comfortable at millions of inputs. Quadratic starts hurting at n ~ 10,000. Exponential is unusable beyond tiny inputs: 2¹⁰⁰ exceeds the number of atoms in the observable universe. This gap between polynomial and exponential isn't just quantitative — it's qualitative, separating tractable from intractable problems in theoretical computer science.

Two companion notations complete the picture. Ω(g(n)) (Omega) is a lower bound: f(n) = Ω(g(n)) means f grows at least as fast as g. Θ(g(n)) (Theta) is a tight bound: f(n) = Θ(g(n)) means f is bounded above and below by multiples of g. In practice, "this algorithm is O(n²)" is an upper-bound claim about one algorithm; "comparison-based sorting requires Ω(n log n)" is a lower-bound claim about all possible sorting algorithms. When both bounds match — as they do for merge sort, which is Θ(n log n) — you have the complete asymptotic picture.

A persistent confusion: Big-O ignores constants, but that doesn't mean constants are irrelevant to real performance. An O(n) algorithm with a huge constant can run slower than an O(n²) algorithm with a tiny constant for all practical input sizes. Big-O describes *asymptotic* behavior — what happens as n → ∞. For the inputs you actually encounter, profiling and benchmarking still matter. The notation is a classification tool, not a performance oracle.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Dividing Integers → Unit Rates → Proportions → Percent Concept → Converting Between Fractions, Decimals, and Percents → Operations with Rational Numbers → Two-Step Equations → Solving Multi-Step Equations → Equations with Variables on Both Sides → Literal Equations → Slope-Intercept Form → Point-Slope Form → Writing Linear Equations → Parallel and Perpendicular Line Slopes → Graphing Linear Equations → Piecewise Functions → Step Functions → Composition of Functions → Inverse Functions → Radical Functions and Graphs → Rational Exponents → Exponential Functions and Graphs → Logarithms Introduction → Big-O Notation and Asymptotic Analysis → Breadth-First Search (BFS) → Shortest Paths in Unweighted Graphs → Dijkstra's Shortest Path Algorithm → Algorithm Analysis and Big-O Notation → Algorithm Complexity and Big-O Notation

Longest path: 81 steps · 411 total prerequisite topics

Prerequisites (1)

Leads To (1)