Asymptotic Notation: GATE CS Previous Year Questions

Asymptotic Notation · Algorithms

40 questions · asked in 21 of 27 years (2000–2026)

MCQ 37 · MSQ 2 · NAT 11-mark 27 · 2-mark 13

2000Questions per year2026

Questions 26–30 of 40

Q26GATE 20071 markMCQ−0.33 if wrong
Consider the following C code segment:
 int IsPrime(n)
{
  int i,n;
  for(i=2;i<=sqrt(n);i++)
     if(n%i == 0)
      {printf("Not Primen"); 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?

Q27GATE 20071 markMCQ−0.33 if wrong
What is the time complexity of the following recursive function:
 int DoSomething (int n) 
{
  if (n <= 2)
    return 1;
  else 
    return (DoSomething (floor(sqrt(n))) + n);
}

Q28GATE 20071 markMCQ−0.33 if wrong
In the following C function, let n≥\geqm.
int gcd(n,m)
{
  if (n%m ==0) return m;  
  n = n%m;
  return gcd(m,n);
}
How many recursive calls are made by this function?

Q29GATE 20061 markMCQ−0.33 if wrong
Consider the following C-program fragment in which i, j,and n are integer variables.
for (i = n, j = 0; i > 0; i/=2, j += i);
Let Val(j) denote the value stored in the variable j after termination of the for loop. Which one of the following is true?

Q30GATE 20051 markMCQ−0.33 if wrong
Consider the following C-function:
 double foo (int n)
{
    int i;
    double sum;
    if (n == 0) return 1.0;
    else
    {
        sum = 0.0;
        for (i = 0; i < n; i++)
            sum += foo (i);
        return sum;
    }
} 
Suppose we modify the above function foo() and store the values of foo (i), 0≤i<n0\leq i \lt n, as and when they are computed. With this modification, the time complexity for function foo() is significantly reduced. The space complexity of the modified function would be:

Keep practising

Topics in Algorithms

All CS topics ›