Recursion — Test 1
Page 1 of 1
Question 1
Given int f(int n){ return n == 0 ? 0 : n + f(n-1); }, what is f(4)?
FPSC- Programmer (BS-17) - Pakistan Meteorological Department (PMD) Model Papers - 2026
Question 2
What happens when a recursive Python function has no reachable base case?
FPSC- Programmer (BS-17) - Pakistan Meteorological Department (PMD) Model Papers - 2026
Question 3
Does CPython optimize tail-recursive calls (tail-call optimization)?
FPSC- Programmer (BS-17) - Pakistan Meteorological Department (PMD) Model Papers - 2026
Question 4
What does p(3) print?
void p(int n){ if(n == 0) return; p(n-1); cout << n; }
FPSC- Programmer (BS-17) - PMD High Yield - 2026
Question 5
What is the time complexity of the naive recursive Fibonacci function fib(n) = fib(n-1) + fib(n-2)?
FPSC- Programmer (BS-17) - PMD High Yield - 2026
Question 6
Which statement about recursion compared with iteration is correct?
FPSC- Programmer (BS-17) - Pakistan Meteorological Department (PMD) Model Papers - 2026