# Recent questions tagged recursion

1
Consider the following $\text{ANSI C}$ program #include <stdio.h> int foo(int x, int y, int q) { if ((x<=0) && (y<=0)) return q; if (x<=0) return foo(x, y-q, q); if (y<=0) return foo(x-q, y, q); return foo(x, y-q, q) + foo(x-q, y, q); } int main( ) { int r = foo(15, 15, 10); printf(“%d”, r); return 0; } The output of the program upon execution is _________
1 vote
2
Consider the following program. Assume that $x$ and $y$ are integers. f(x, y) { if (y != 0) return (x * f(x,y-1)); else return 1; } What is $f(6,3)?$ $243$ $729$ $125$ $216$
1 vote
3
What is the time complexity of the following recursive function? int ComputFun(int n) { if(n<=2) return 1; else return (ComputFun(floor(sqrt(n)))+n); } $\Theta(n)$ $\Theta(\log n)$ $\Theta(n\log n)$ $\Theta(\log \log n)$
4
Choose the correct statements. A total recursive function is also a partial recursive function A partial recursive function is also a total recursive function A partial recursive function is also a primitive recursive function None of the above
1 vote
5
A recursive function $h$, is defined as follows: $\begin{array} {} h(m) & =k, \text{if } m=0 \\ &=1, \text{if } m=1 \\ &= 2 h(m-1)+4h(m-2), \text{if } m \geq 2 \end{array}$ If the value of $h(4)$ is $88$ then the value of $k$ is: $0$ $1$ $2$ $-1$
6
#include<iostream> using namespace std; int i=0; void a() { i+=1; cout<<i<< ".hello"<<endl; a(); } int main() { a(); } For this above code the output is only upto → 64891.Hello Does this mean that that the stack can hold only 64891 recursive calls? (I am using dev c++)
7
Consider the following function: void madeeasy (int n) { if (n < 0) return; else { printf(n); madeeasy (- -n); madeeasy (n - -); printf(n); } } The sum of all values printed by madeeasy (5)_______ (I am getting -12 but given answer is 52)
1 vote
8
9
Consider the function: int fun(int n) { if (n==4) return n; else return 2*fun(n+1); } A MOD-16 ripple counter is holding the count $(1001)_2.$ What will be the count after "$(\text{fun}(2)+15)_{10}$" clock pulses? $(1000)_2$ $(1010)_2$ $(1011)_2$ $(1101)_2$
10
Consider the two given functions: int fun1(int x, int y) { if (y==0) return 0; return (x+fun2(x, y-1)); } int fun2(int x, int y) { if (x==0) return y; return fun2(x-1, x+y); } What will be the value returned by $\text{fun1}(4, 4)$ ____
11
#include <stdio.h> void print(int n, int j) { if (j >= n) return; if (n-j > 0 && n-j >= j) printf("%d %dn", j, n-j); print(n, j+1); } int main() { int n = 8; print(n, 1); } (A) 1 7 2 6 3 5 4 4 4 4 (B) 1 7 2 6 3 5 4 4 (C) 1 7 2 6 3 5 (D) 1 2 3 4 5 6 7 8 Answer is B. anyone can explain how?
12
T(n) = sqrt(n) * T(sqrt(n)) + n Given solution is O(log log n). But my solution is O(n log log n). 'wolframalpha'' shows the answer same as mine. You can find the solution here. Can anyone confirm the solution and provide an explantion?
13
1 vote
14
Does Heap Allocation support both recursion and dynamic memory allocation? Because,a stack can be implemented using dynamic memory allocation.Please correct me. Test Series answer shows only dynamic memory allocation
1 vote
15
What is Head recursion and Tail Recursion??
16
1 vote
17
int zap(int n) { if (n<=1) then zap =1; else zap = zap(n-3)+zap(n-1); } then the call zap(6) gives the values of zap Give the proper explanation
18
#include <stdio.h> void fun(int); typedef int (*pf) (int ,int ); int proc(pf, int ,int); int main() { int a = 3; fun(a); return 0; } void fun(int n) { if (n>0) { fun(--n); printf("%d,", n); fun(--n); } }
19
How to trace the below program? p and q are the starting address of two different linked list struct node*Do(struct node*p,struct node*q){ struct node*ps,*qs; if(!p){ return(q); } else if(!q){ return(p); } else{ ps=p->link; qs=q->link; p->link=q; q->link=Do(ps,qs); return(p); } }
20
int f (int n){ if (n==0) return 0; if(n==1) return 1; else return f(n-1)+f(n-2); } Find the upper bound and lower bound to the number of function calls for input size 'n'?
1 vote
21
void ab() { auto int a; static int s= 5; a = ++s; printf("%d%d",a,s); if(a<= 7) ab(); printf("%d%d",a,s); } void main() { ab(); } According to me answer should be- 667788887766 but the answer is - 667788887868. Please explain
22
Consider the following program written in pseudo-code. Assume that x and y are integers. Count (x, y) { if (y !=2 ) { if (x !=1) { print("*"); Count (x/2, y); } else { y=y-1; Count (1024, y); } } } The number of times that the print statement is executed by the call Count(1024,1024 ... =========================================== My answer is 10220 and I just need someone to verify if it's correct.
Why is recursive equation of following code $T(n)=T(n/2)+O(1)$, not $T(n)=8*T(n/2)+O(1)$? int x=0; int A(n) { if(n==1) return 1; else { X+=8A(n/2)+n^3; } return X; }