1
GATE CSE 2008
MCQ (Single Correct Answer)
+2
-0.6
Consider the following C functions:
int f1(int n){
 if(n == 0 || n == 1){
    return n;
 }
 return (2 * f1(n - 1) + 3 * f1(n - 2));
}
int f2(int n){
 int i;
 int X[N], Y[N], Z[N];
 X[0] = Y[0] = Z[0] = 0;
 X[1] = 1; Y[1] = 2; Z[1] = 3;
 for(i = 2; i <= n; i++){
  X[i] = Y[i - 1] + Z[i - 2];
  Y[i] = 2 * X[i];
  Z[i] = 3 * X[i];
 }
 return X[n];
}
The returning time of f1(n) and f2(n) are
A
$$\Theta \,(n)\,and\,\Theta \,(n)$$
B
$$\Theta \,({2^n})\,and\,\Theta \,(n)$$
C
$$\Theta \,(n)\,and\,\Theta \,({2^n})$$
D
$$\Theta \,({2^n})\,and\,\Theta \,({2^n})$$
2
GATE CSE 2008
MCQ (Single Correct Answer)
+2
-0.6
Consider the following C functions:
int f1(int n){
 if(n == 0 || n == 1){
    return n;
 }
 return (2 * f1(n - 1) + 3 * f1(n - 2));
}
int f2(int n){
 int i;
 int X[N], Y[N], Z[N];
 X[0] = Y[0] = Z[0] = 0;
 X[1] = 1; Y[1] = 2; Z[1] = 3;
 for(i = 2; i <= n; i++){
  X[i] = Y[i - 1] + Z[i - 2];
  Y[i] = 2 * X[i];
  Z[i] = 3 * X[i];
 }
 return X[n];
}
f1(8) and f2(8) return the values
A
1661 and 1640
B
59 and 59
C
1640 and 1640
D
1640 and 1661
3
GATE CSE 2007
MCQ (Single Correct Answer)
+2
-0.6
What is the time complexity of the following recursive function?
int DoSomething(int n){
 if(n <= 2)
     return 1;
 else
     return (floor(sqrt(n)) + n);
}
A
$$\Theta \,({n^2})$$
B
$$\Theta \,(n\,{\log _2}\,n)$$
C
$$\Theta \,({\log _2}\,n)$$
D
$$\Theta \,({\log _2}\,{\log _2}\,n)$$
4
GATE CSE 2007
MCQ (Single Correct Answer)
+2
-0.6
Consider the following C code segment:
int IsPrime(n){
 int i, n;
 for(i=2; i<=sqrt(n);i++){
  if(n % i == 0){
    printf("No prime\n"); return 0;
  }
  return 1;
 }
}
Let T(n) denote the number of times the for loop is executed by the program on input n. Which of the following is TRUE?
A
T(n) = O ($$\sqrt n $$) and T(n) = $$\Omega \,(\sqrt n )$$
B
T(n) = O ($$\sqrt n $$) and T(n) = $$\Omega \,(1)$$
C
T(n) = O (n) and T(n) = $$\Omega \,(\sqrt n )$$
D
None of the above
GATE CSE Subjects
Software Engineering
Web Technologies
EXAM MAP
Medical
NEET
Graduate Aptitude Test in Engineering
GATE CSEGATE ECEGATE EEGATE MEGATE CEGATE PIGATE IN
CBSE
Class 12