Skip to content
ExamRizzInterview readingReading
Leave

STEM · Computer Science · Foundational Concepts/Principles

Save

Recursion and Induction

Significance: Recursion solves problems by reducing to smaller instances. Induction proves properties by establishing base case and inductive step. These are dual concepts: recursive programs correspond to inductive proofs. Recursion enables elegant solutions (tree traversal, divide-and-conquer). Understanding recursion requires understanding call stack, base cases, and how recursive calls combine.

Questions to think through

  1. Explain recursion: Write recursive factorial: `f(n) = n * f(n-1)`, base: `f(0) = 1`. Trace execution for f(3), showing call stack. Why is base case essential (without it, infinite recursion)? Convert to iterative form. Explain tail recursion: last operation is recursive call, enabling optimization to iteration. Is factorial tail-recursive? How would you make it tail-recursive using accumulator?

    explain
  2. Prove using induction: Binary tree with n nodes has exactly n-1 edges. Base: n=1 (just root), 0 edges. Inductive step: assume true for trees with k nodes. Tree with k+1 nodes: root + left subtree (i nodes, i-1 edges) + right subtree (j nodes, j-1 edges), where i+j=k. Total edges = 1 (root to children) + (i-1) + (j-1) = 1 + k - 2 = k = (k+1) - 1. Explain how this proof structure mirrors recursive tree algorithms.

    explain

Recursion · Mathematical Induction · Call Stack · Tail Recursion · Divide-and-Conquer · Proofs