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 moreAmortized 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 ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesBoolean AlgebraBoolean Type and Truth ValuesComparison Operators and Boolean TestsLogical Operators and Boolean AlgebraConditional StatementsDefining and Calling FunctionsFunctions: Decomposing ProblemsFunction Parameters and Argument PassingReturn ValuesVariable ScopeIntroduction to ClassesObjects and InstancesMethods and AttributesAlgorithm Design BasicsRecursion and Tail-Recursion OptimizationAnalyzing Recursive Algorithms via Recurrence Relations

Longest path: 84 steps · 400 total prerequisite topics

Prerequisites (3)

Leads To (3)