Branching Recursion and Multiple Work

Intermediate Algorithms and Data Structures English
Also available: Deutsch
Created by Best · 16.08.2026 at 09:13 UTC

Branching recursion generates multiple calls per frame, such as naive Fibonacci: fib(n) = fib(n-1) + fib(n-2). The number of calls grows exponentially, and many subproblems are repeated.

Countermeasures: Memoization, dynamic programming, or closed formulas.

Be able to distinguish the complexity of the naive variant from the linear DP variant.

Diagram

$$T(n)=T(n-1)+T(n-2)+\Theta(1)$$

The same split, linear work: Fibonacci Number [1].

Where used

Unmemoized search trees, naive recursive layouts, exponential parser variants. The same structure is found in Divide-and-Conquer (Merge Sort) and in Backtracking; the difference is whether subproblems overlap and whether results are stored.

Depth

In branching recursion, multiple subproblems arise from a single problem. The runtime depends not only on the depth but also on the number of nodes in the resulting call tree.

Naive Fibonacci computation repeatedly solves the same arguments. Memoization stores results by argument and reduces the call tree to the number of different subproblems. Dynamic programming calculates the same dependencies in an ordered manner without recursion.

Not every branching means duplicate work. In Divide-and-Conquer methods, disjoint subproblems can occur; then the work for splitting and combining additionally determines the recurrence.

Difficulty levels

  1. Draw a small call tree.
  2. Distinguish between repeated and disjoint subproblems.
  3. Analyze a recurrence with memoization or divide-and-conquer structure.

Pitfalls

The recursion depth alone does not describe the runtime. Memoization helps only when states are unambiguous and can be stored as keys with reasonable effort.


Sources

University approvals: 0
Tasks
Question 1

Why is naive recursive Fibonacci costly?

Question 2

When does memoization reduce work particularly significantly?

Question 3

Calculate Fibonacci numbers recursively using a memo array.

Hint

An array element is read or written using memo[index]. The existing value -1 serves as an unset marker.

Starter code is prefilled; replace TODO blocks with your solution.
1 test case will be used for grading
Run checks runtime behavior only. Final correctness is evaluated when you submit.
Card Info
  • Topic: Algorithms and Data Structures
  • Difficulty: Intermediate
  • Completed: 0 users
Creator
Best
Best
BestBuddy