Time Left - 15:00 mins

# GATE 2021 : data structure and programming 5

Attempt now to get your rank among 950 students!

Question 1

The time complexity of the following c function is (assum n>0)

int  recursive(int n){

if(n==1)

return(1);

else

return (recursive(n-1)+ recursive(n-1));

}

Question 2

Consider the following recursive C function that takes two arguments.
unsigned int foo(unsigned int n, unsigned int r){
if (n > 0) return ((n%r) + foo(n/r, r));
else return 0;
}
What is the return value of the function foo when it is called as foo (345, 10)?

Question 3

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

Question 4

If a base condition isn’t specified in a recursive program, what will it lead to?

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 f(n) be the number of values printed. What is the number of values printed by above function?

Question 6

Consider the following two functions.
void fun1 (int n) {
if (n == 0 ) return;
printf (“%d” , n);
fun2 (n - 2);
printf (“%d” , n);
}
void fun2 (int n) {
if (n = = 0) return ;
printf (“%d” , n);
fun1(++n) ;
printf (“%d” , n);
}
The output printed when fun1(5) is called is
• 950 attempts
• 1 upvote