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

Complexity Classes and Asymptotic Analysis

College Depth 80 in the knowledge graph ☐ I know this ☆ Set as goal
28topics build on this
411prerequisites beneath it
See this on the map →
Algorithm Analysis and Big-O Notation→→NP-Completeness
algorithms complexity

Core Idea

Standard complexity classes ordered by growth: O(1) constant, O(log n) logarithmic, O(n) linear, O(n log n), O(n²) quadratic, O(2n) exponential, O(n!) factorial. Each class represents fundamentally different algorithm scalability and feasibility on large inputs.

Explainer

You already know that big-O notation describes how an algorithm's runtime grows relative to input size n. Complexity classes organize that idea into a hierarchy of qualitatively different behaviors. The key insight is that these classes are not just faster or slower versions of each other — they represent fundamentally different scalability. An O(n²) algorithm and an O(n) algorithm are not just "one slower" — at n = 1,000,000, the O(n) algorithm might take a second while the O(n²) takes 11 days.

Start at the bottom of the hierarchy. O(1) constant time means the algorithm takes the same effort regardless of input size — looking up an element in a hash table, or reading the first item of a list. O(log n) logarithmic time is nearly as good: binary search on a sorted list of a billion items takes about 30 comparisons, because each comparison halves the remaining search space. Any time you can discard half the problem at each step, you get a logarithm. O(n) linear time means you must touch every element once — scanning a list for a value, computing a sum. This is the natural floor for problems that require reading all their input.

The middle classes represent common algorithmic tradeoffs. O(n log n) is the complexity of efficient comparison-based sorting algorithms (merge sort, heapsort). It's the cost of repeatedly halving — you do O(log n) work, and you must do it for each of the O(n) elements. O(n²) quadratic arises from nested loops over the input — comparing every element to every other element. Bubble sort and insertion sort are O(n²). For n = 10,000 items, that's 100 million operations — still manageable. At n = 1,000,000, it's a trillion.

The upper classes are qualitatively infeasible for large inputs. O(2n) exponential means the work doubles with each additional element. Brute-force search over all subsets of n items, solving the traveling salesman problem by checking all routes — these are O(2n). For n = 50, that's over a quadrillion operations. O(n!) factorial is worse still — generating all permutations of n items. For n = 20, that's over 2 quintillion operations. These classes are not just "slow" — they are computationally intractable for any realistic input. The dividing line between polynomial time (O(nk) for some fixed k) and superpolynomial time (O(2n), O(n!)) is the central distinction in theoretical computer science, and it motivates the entire P vs NP question.

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 → Complexity Classes and Asymptotic Analysis

Longest path: 81 steps · 411 total prerequisite topics

Prerequisites (1)

Leads To (1)