Recursive Programs questions

Q61

GATE CS 2026 CS-1RecursionNAT2 marks
Consider the recursive functions represented by the following code segment:
int bar(int n){
 if (n == 1) return 0;
 else return 1 + bar(n/2);
}

int foo(int n){
 if (n == 1) return 1;
 else return 1 + foo(bar(n));
}
The smallest positive integer n for which foo(n) returns 5 is ______. (answer in integer)

Note: Ignore syntax errors (if any) in the function.
Show answer without attempting

Answer: 65536

Q61

GATE CS 2026 CS-2RecursionNAT2 marks
Consider the following ANSI-C function.
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.
Show answer without attempting

Answer: 1

0/20 correct0 marks