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

Analyzing Recursive Algorithms via Recurrence Relations

College Depth 83 in the knowledge graph ☐ I know this ☆ Set as goal
155topics build on this
400prerequisites beneath it
See this on the map →
Asymptotic Notation: Big-O, Big-Omega, Big-ThetaRecursion Basics+1 more→→Amortized AnalysisDivide and Conquer+1 more
recursion recurrence analysis

Core Idea

Recursive algorithms can be analyzed by setting up recurrence relations—equations describing the running time T(n) in terms of T(n/2), T(n-1), or other smaller inputs. Solving these relations (via substitution, recurrence trees, or the master theorem) yields closed-form complexity bounds.

How It's Best Learned

Trace recursive calls for small inputs, build a recurrence tree to visualize, then apply master theorem or substitution method. Compare on examples like T(n) = T(n/2) + O(n) for binary search.

Common Misconceptions

Explainer

When you write a recursive algorithm, the code itself tells you what happens at each level — divide the input, do some work, recurse on smaller pieces. But to know the algorithm's overall running time, you need to translate that recursive structure into a mathematical equation and solve it. This equation is a recurrence relation: it expresses T(n), the time to solve a problem of size n, in terms of the time to solve smaller subproblems plus the non-recursive work at the current level.

Take binary search as a starting example. At each step, you compare the target to the middle element (O(1) work), then recurse on one half. The recurrence is T(n) = T(n/2) + O(1). Merge sort is different: you split the array in two, recurse on both halves, then merge the results in O(n) time. Its recurrence is T(n) = 2T(n/2) + O(n). Notice how the recurrence captures two things your Big-O prerequisite taught you to care about — how many subproblems you create and how much work you do at each level. The base case, typically T(1) = O(1), anchors the recursion.

The recursion tree method is the most intuitive way to solve these. Draw each recursive call as a node, labeling it with the non-recursive work at that level. For merge sort, the root does O(n) work and spawns two children, each doing O(n/2) work. Each of those spawns two more at O(n/4). At every level, the total work sums to O(n), and there are log₂(n) levels, giving O(n log n) total. For binary search, each level does O(1) work with one child, so the total across log₂(n) levels is O(log n). The tree makes the pattern visible: you sum the work across all levels.

The substitution method takes a guess-and-verify approach. You hypothesize that T(n) = O(n log n) for merge sort, substitute into the recurrence, and prove by induction that the bound holds. This is rigorous but requires a good initial guess — which is why the recursion tree is often used first to build intuition, then substitution to prove it formally. For recurrences that fit the pattern T(n) = aT(n/b) + O(nd), the master theorem gives the answer directly by comparing log_b(a) to d. If they are equal, you get O(nd log n). If log_b(a) is larger, the recursive calls dominate. If d is larger, the non-recursive work dominates. Merge sort has a = 2, b = 2, d = 1, and since log₂(2) = 1 = d, you immediately get O(n log n). Learning to set up the recurrence correctly — identifying a, b, and the cost of the non-recursive work — is the core skill. The solving techniques are mechanical once the recurrence is right.

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 → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Conditional Statements → Defining and Calling Functions → Functions: Decomposing Problems → Function Parameters and Argument Passing → Return Values → Variable Scope → Introduction to Classes → Objects and Instances → Methods and Attributes → Algorithm Design Basics → Recursion and Tail-Recursion Optimization → Analyzing Recursive Algorithms via Recurrence Relations

Longest path: 84 steps · 400 total prerequisite topics

Prerequisites (3)

Leads To (3)