Recursion formulas
Recursion: tracing recursive programs. 5 formulas for GATE CS Programming in C, each with when to use it. Each is explained in the topic notes.
IAE Academy: Recursion: tracing recursive programs formulas (GATE CS)
All 5 Recursion formulas
CALL COUNT: SINGLE (LINEAR) RECURSION
For a function that makes exactly one recursive call, on , and stops at n == 0 without a further call (for example, a factorial with base case n == 0). counts the initial call and the base-case call. If the base case is at n == 1 instead (with ), the count is . Always check where the base case fires.
CALL COUNT: HALVING RECURSION
For a function that makes one recursive call on n / 2 (integer division) and stops at n == 0, like bin above. The calls that print or do work (those with ) number , which is the number of bits of . The extra call is the base case n == 0.
CALL COUNT: NAIVE FIBONACCI (TWO CALLS, ON N-1 AND N-2)
For a function with base cases n == 0 and n == 1 that makes no further calls, and otherwise calls itself on and . The counts the current call. is the standard Fibonacci sequence . Of the calls, are base-case calls (leaves) and make further calls. The count grows as , where .
UNROLLING SINGLE RECURSION ON N-1
Holds when each non-base call does a constant amount of work and makes exactly one recursive call on , and the base case at costs . Substitute repeatedly: , then put .
TWO RECURSIVE CALLS ON N-1 (TOWER OF HANOI MOVES)
Unrolling gives ; put . The same shape counts calls when the base case is n == 0 and is itself counted: .
Where this was asked: 2018 (2), 2020 (1), 2023 (2), 2024 (1), 2025 (1), 2026 (2). See the 9 previous-year questions on Recursion. This shows what was asked, not what will be asked.