Course contentsShow
← Computer Science
Lesson 226 of 2,8725. Functions and ModularityFree lesson

Multiple Recursive Calls

Work with functions that make multiple recursive calls, such as tree traversals or combinatorial problems.

Multiple Recursive Calls

What you'll learn: How a single function can call itself more than once, branching into multiple paths of recursion.

The Core Idea

So far, you've seen recursion where a function calls itself once per execution—like computing a factorial or counting down. But some problems naturally split into multiple smaller versions of the same problem. When this happens, your function makes multiple recursive calls in one execution.

Think of it like a family tree: each person (except those at the bottom) has multiple children. To explore the whole tree, you'd need to visit each child branch separately. Similarly, a function might need to explore multiple "branches" of a problem.

How It Works

When a function makes multiple recursive calls, each call is independent and goes onto the call stack separately. The function waits for all recursive calls to complete before combining their results.

Classic example: The Fibonacci sequence you've seen makes two recursive calls:

  • fib(n-1) — one branch
  • fib(n-2) — another branch

Each of these spawns its own set of recursive calls, creating a tree-like structure of function calls.

Why This Matters

Many real problems naturally decompose into multiple sub-problems:

  • Tree traversals: visiting each child node of a tree
  • Combinatorial problems: finding all possible combinations or arrangements
  • Divide-and-conquer algorithms: splitting data into multiple parts

Multiple recursive calls create more complex call stacks than single recursion, so understanding the branching structure helps you trace execution and avoid stack overflow.

Key Takeaway: Multiple recursive calls let functions branch into several independent sub-problems, each solving a smaller version of the original task—essential for tree-like and combinatorial problems.