Sign in to track progress, unlock prep layers, and browse your pipeline.Sign in
Count calls in recursive function evaluation
Problem Description
Consider the following recursive function in C-like pseudocode:
int x(int n) {
if (n <= 3) return 1;
else return x(n - 2) + x(n - 4) + 1;
}
When computing x(8), how many times in total is function x called (including the initial call x(8) itself)?
AI interview prep
Core dilemma
Optimizing the computation of a recursive function by identifying and eliminating redundant calculations, specifically focusing on counting function calls rather than just the return value.
Mid-level signals3
Senior signals3
Red flags3
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Count calls in recursive function evaluation
Problem Description
Consider the following recursive function in C-like pseudocode:
int x(int n) {
if (n <= 3) return 1;
else return x(n - 2) + x(n - 4) + 1;
}
When computing x(8), how many times in total is function x called (including the initial call x(8) itself)?