
Learn core concepts, essential formulas, and attempt practice questions designed on the latest TCS NQT testing patterns.
What is output of: int f(int n) { if(n<=1) return 1; return n * f(n-1); } for f(3)?
Correct Answer: A) 6
Step-by-step Solution: f(3) = 3 * f(2) = 3 * (2 * f(1)) = 3 * 2 * 1 = 6. (Factorial sequence).
What error occurs if a recursive function lacks a base case?
Correct Answer: A) Stack Overflow
Step-by-step Solution: Infinite recursion exhausts the system call stack memory, triggering a Stack Overflow crash.
Trace function variables on paper step-by-step for recursion tracing questions.