Recursion and Decomposition

  1. Choosing a Base Case for Recursion

    A base case produces an answer directly for an input that needs no further recursive work.

    Undergraduate
  2. Making Each Recursive Call Smaller

    A recursive decomposition has to make progress toward a base case under a well-founded measure.

    Undergraduate
  3. Tracing a Recursive Call Stack

    Each active invocation keeps its own local values and the work to resume when a nested call returns.

    Undergraduate
  4. Tail Calls and Accumulated State

    A tail call is made when its result can become the current function's result without further computation.

    Undergraduate
  5. Counting Nodes in a Tree Recursively

    A tree can be counted by adding each node to the sizes of all its child subtrees. An empty subtree contributes zero.

    Undergraduate
  6. Measuring Tree Height Recursively

    Tree height describes the longest root-to-leaf path. Decide whether the measure counts edges or nodes.

    Undergraduate
  7. Tracing Preorder and Postorder Tree Visits

    The position of a node's action relative to its children determines whether the traversal processes parents before or after descendants.

    Undergraduate
  8. Collecting the Leaves of a Tree

    To collect leaves in order, emit the current node if it has no children. Otherwise traverse its children in their declared order.

    Undergraduate
  9. Divide, Solve, and Combine

    Divide and conquer splits a problem into smaller instances, solves them, and combines the answers using a rule tied to the goal.

    Undergraduate
  10. Splitting a Half-Open Interval Recursively

    Two half-open subintervals can cover a segment exactly once and give clear stopping conditions for recursive processing.

    Undergraduate
  11. Binary Search by Hand

    Binary search repeatedly uses sorted order to discard positions that cannot contain the desired value or boundary.

    Undergraduate
  12. Merging Two Sorted Sequences

    Merging selects the smaller current head from two sorted sources until both sources are exhausted.

    Undergraduate
  13. Counting Recursive Calls

    The time used by recursion depends on the number of invocations and the cost inside each one. Stack depth measures only the longest active path.

    Undergraduate
  14. Recognizing Overlapping Recursive Subproblems

    Recursive calls overlap when different branches request the same subproblem. Reusing its answer can avoid repeating an entire subtree of work.

    Undergraduate
  15. Memoizing a Recursive Function

    Memoization saves a finished answer under the state that produced it and reuses that answer for later requests for the same state.

    Undergraduate
  16. Evaluating a Recurrence from the Bottom Up

    A bottom-up evaluation records base values first and computes larger states in an order respecting all dependencies.

    Undergraduate
  17. Replacing Recursion with an Explicit Worklist

    An explicit worklist stores pending tasks in ordinary data structures. Its ordering governs which task the traversal performs next.

    Undergraduate
  18. Handling Deep Recursive Inputs

    Even a terminating recursion can reach a depth beyond the runtime's available stack or a configured recursion limit.

    Undergraduate
  19. Reading a Small Recursive Grammar

    A recursive grammar can describe arbitrarily deep nested structures using a limited set of production rules.

    Undergraduate
  20. Walking Nested Records and Lists

    Recursive traversal can visit values in nested records by handling containers and leaf values according to their shape.

    Undergraduate
  21. Backtracking and Choice Points

    Backtracking tries a choice, explores its consequences, and restores the state needed to try another choice.

    Undergraduate
  22. Generating Subsets by Inclusion Choices

    For each distinct item, a recursive generator can branch into including it and leaving it out. The base case records the completed choices.

    Undergraduate
  23. Generating Permutations by Choosing the Next Item

    To enumerate input permutations, choose each possible first item and recursively enumerate arrangements of what remains.

    Undergraduate
  24. Pruning an Impossible Branch

    Pruning skips descendants of a search state when a justified bound establishes that none can satisfy the goal.

    Undergraduate
  25. Processing a List as First Item and Remainder

    A list computation can separate the first item from the rest and combine the first contribution with the result for the remainder.

    Undergraduate
  26. Processing Digits with Quotient and Remainder

    Repeated division by the base can separate an integer into its least significant digit and the digits that precede it.

    Undergraduate
  27. Structural Induction on Lists

    Structural induction proves a property for empty input and shows how extending an arbitrary shorter list preserves that property.

    Undergraduate
  28. Induction on Tree Shapes

    A structural proof for finite trees shows the claim for the smallest tree and assumes it for each child when proving it for a larger node.

    Undergraduate
  29. Reasoning About Mutual Recursion

    Mutually recursive functions call one another. Their combined transitions must reach a base case for every allowed input.

    Undergraduate
  30. Balancing Recursive Subproblem Sizes

    The shape of recursive splits affects maximum depth and the amount of work. A split that removes one item can be much deeper than halving the size.

    Undergraduate