Time Left - 15:00 mins
GATE 2019 - Programming & Data Structure Quiz-2
Attempt now to get your rank among 1192 students!
Question 1
Consider the following function:
What is the number of recursive calls made by the above function considering the assumption that n>=m?
What is the number of recursive calls made by the above function considering the assumption that n>=m?
Question 2
Consider the following recursive c function:
void ABC (int i)
{
if(i<1)
return;
ABC(i-2);
ABC(i-4);
printf(“%d”, i);
}
If ABC (6) function is being called in main () then how many times will the ABC() function be invoked before returning to the main()?
void ABC (int i)
{
if(i<1)
return;
ABC(i-2);
ABC(i-4);
printf(“%d”, i);
}
If ABC (6) function is being called in main () then how many times will the ABC() function be invoked before returning to the main()?
Question 3
Consider the following rec function.
rec(int x)
{
static int f;
if (x==1)
return(1);
else
f+=x*rec(x-1);
return(f);
}
Find the value returned by rec(5).
rec(int x)
{
static int f;
if (x==1)
return(1);
else
f+=x*rec(x-1);
return(f);
}
Find the value returned by rec(5).
Question 4
Consider the following recursive C function.
If get (6) function is being called in main () then how many times will they get ()
Function be invoked before returning to the main ()?
If get (6) function is being called in main () then how many times will they get ()
Function be invoked before returning to the main ()?
Question 5
Consider the following function.
void f(int n)
{
if (n 0) return;
else
{
print (n);
f(n-2);
print (n);
f(n-1);
}
}
Let R(n) be the recurence relation which computes the sum of values printed by the f(n). The R(n) is
void f(int n)
{
if (n 0) return;
else
{
print (n);
f(n-2);
print (n);
f(n-1);
}
}
Let R(n) be the recurence relation which computes the sum of values printed by the f(n). The R(n) is
Question 6
What is the value returned by the following function when x=1 and y=3?
int f (int x, int y)
{
if(x==0 && y>=0) return y + 1;
else if (x > 0 && y== 0) return f(x-1,1);
else if (x > 0 && y>0) return (f(x-1, f(x, y-1)));
}
int f (int x, int y)
{
if(x==0 && y>=0) return y + 1;
else if (x > 0 && y== 0) return f(x-1,1);
else if (x > 0 && y>0) return (f(x-1, f(x, y-1)));
}
- 1192 attempts
- 4 upvotes
- 9 comments
Oct 14GATE & PSU CS