Time Left - 30:00 mins

GATE CS 2018 - Data Structures Quiz 7

Attempt now to get your rank among 613 students!

Question 1

Which of the options are correct with respect to Tower of Hanoi problem ?

Question 2

Consider the function f defined below.
struct item {
int data;
struct item * next;
};
int f(struct item *p) {
return ((p == NULL) || (p ->next == NULL) ||
((p->data <= p -> next -> data) &&
f(p-> next)));
}
For a given linked list p, the function f returns 1 if and only if

Question 3

Consider the following pseudo code. What is the total number of multiplications to be performed?
D = 2
for i = 1 to n do
for j = i to n do
for k = j + 1 to n do
D = D * 3

Question 4

What is the return value of f(p, p) if the value of p is initialized to 5 before the call? Note that the first parameter is passed by reference, whereas the second parameter is passed by value.

int f(int &x, int c) {
   c  = c - 1;
   if (c == 0) return 1;
   x = x + 1;
   return f(x, c) * x;
  } 

Question 5

What is the sum of outputs printed by running the following program?
int main ( )
{
int i ;
for (i = 3; i < = 6; i++)
printf(“%d”, f1(i));
}
int f1 (int n)
{
if (n < 2) return n;
else return (f1(n –1) + f2(n – 2));
}
int f2 (int n)
{
if (n < = 1) return n;
else return (2 f1 (n – 2) + 1);
}
  • 613 attempts
  • 7 upvotes
  • 18 comments
Mar 26GATE & PSU CS