Programming and Data Structures · Recursion
Official IIT answer key · IIT Roorkee · Audited Aug 2026
GATE CSE 2026 Set 2 Q61 · NAT · 2 marks
int func(int start, int end){
int length=end+1-start;
if((length<1)||(start<0)||(end<0)){ return(0); }
if(length%3==0){
return(func(start+1, end));
} else if(length%3==1){
return(1+func(start, end-1));
} else {
return(func(start+2, end));
}
}
The maximum possible value that can be returned from this function is __________. (answer in integer)
Note: Ignore syntax errors (if any) in the function.Key concept
No account needed
Sit 5 related RecursionPYQs as a guest. We'll score the set and show which traps cost marks — sign in only if you want to save the run.
Topic notes
GATE tests Recursion primarily through direct execution tracing of recursive C code snippets, stack-unwinding behavior (pre-order vs. post-order execution), and termination/infinite recursion analysis. Questions frequently incorporate static variables, pointer/reference aliasing, mutual recursion, and tree/array traversals to test whether candidates can systematically maintain call frames. In recent years, the focus has expanded from standard tracing to higher-order mathematical characterizations (e.g., finding the smallest input or maximum output value of composed recurrences).
Full Recursion guide →Consider the following ANSI-C function. int func(int start, int end) int length=end+1-start; if((length The maximum possible value that can be returned from this function is … (answer in integer) Note: Ignore syntax errors (if any) in the function.
Topic-wise GATE CS PYQs with verified steps
Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.
