Recent questions tagged recursion

5 votes
5 answers
181
______ is the number of moves of the smallest disc in Tower of Hanoi implementation where the tower consisting of 17 discs (numbered from 0 to 16)Answer given: $2^{16}$ ...
1 votes
1 answer
182
1 votes
1 answer
183
void xyz(char *s) { if(s[0]=='\0') return; xyz(s+1); xyz(s+1); printf("%c",s[0]); } void main() { xyz("123"); }if the input string constant is of length $n$ then what is ...
1 votes
1 answer
187
I have already gone through the links of stackoverflow on this topic but still couldn't understand it clearly , so please explain the logic behind this .
0 votes
1 answer
188
A(n) { if(n>=1) { A(n-1); // statement 1 print n; //statement 2 A(n-1);// statement 3 } }
0 votes
4 answers
190
int foo(unsigned int n) { int c,x=0; while(n!=0) { if(n&01) x++; n>>=1; } return c; }
15 votes
4 answers
193
Consider the code fragment written in C below :void f (int n) { if (n <=1) { printf ("%d", n); } else { f (n/2); printf ("%d", n%2); } }What does f(173) print?$010110101$...
59 votes
4 answers
198
Consider the following function.double f(double x){ if( abs(x*x - 3) < 0.01) return x; else return f(x/2 + 1.5/x); }Give a value $q$ (to $2$ decimals) such that $f(q)$ wi...
29 votes
6 answers
199
What value would the following function return for the input $x=95$?Function fun (x:integer):integer; Begin If x 100 then fun = x – 10 Else fun = fun(fun (x+11)) End;$...
53 votes
5 answers
200
double foo(int n) { int i; double sum; if(n == 0) { return 1.0; } else { sum = 0.0; for(i = 0; i < n; i++) { sum += foo(i); } return sum; } }The space complexity of the a...
64 votes
8 answers
204
26 votes
1 answer
205
Consider the following C function:int f(int n) { static int r = 0; if (n <= 0) return 1; if (n 3) { r = n; return f(n-2) + 2; } return f(n-1) + r; }What is the value of ...
28 votes
3 answers
206
Consider the following C function:int f(int n) { static int i = 1; if(n >= 5) return n; n = n+i; i++; return f(n); }The value returned by $f(1)$ is:$5$$6$$7$$8$
33 votes
8 answers
210