• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top MCQs on Complexity Analysis of Algorithms with Answers

Question 21

The minimum number of comparisons required to find the minimum and the maximum of 100 numbers is ______________.
  • 148
  • 147
  • 146
  • 140

Question 22

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
  • Half of the product of the 3 consecutive integers.
  • One-third of the product of the 3 consecutive integers.
  • One-sixth of the product of the 3 consecutive integers.
  • None of the above.

Question 23

Consider the following C-function: 

C
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;
    }
}

The space complexity of the above function is:

  • O(1)

  • O(n)

  • O(n!)

  • O(nn)

Question 24

Consider the following C-function: C
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 < 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:
  • O(1)
  • O(n)
  • O(n!)
  • O(nn)

Question 25

Two matrices M1 and M2 are to be stored in arrays A and B respectively. Each array can be stored either in row-major or column-major order in contiguous memory locations. The time complexity of an algorithm to compute M1 × M2 will be
  • best if A is in row-major, and B is in column- major order
  • best if both are in row-major order
  • best if both are in column-major order
  • independent of the storage scheme

Question 26

Let A[1, ..., n] be an array storing a bit (1 or 0) at each location, and f(m) is a function whose time complexity is θ(m). Consider the following program fragment written in a C like language: C
counter = 0;
for (i = 1; i < = n; i++)
{ 
      if (A[i] == 1) 
         counter++;
      else {
         f(counter); 
         counter = 0;
      }
}
The complexity of this program fragment is
  • Ω(n2)
  • Ω(nlog n) and O(n2)
  • θ(n)
  • O(n)

Question 27

The recurrence equation
T(1) = 1
T(n) = 2T(n - 1) + n, n ≥ 2 
evaluates to a. 2n + 1- n - 2 b. 2n - n c. 2n + 1 - 2n - 2 d. 2n + n
  • a
  • b
  • c
  • d

Question 28

Consider the following three claims
1. (n + k)m = Θ(nm), where k and m are constants
2. 2n + 1 = O(2n)
3. 22n + 1 = O(2n) 
Which of these claims are correct ?
  • 1 and 2
  • 1 and 3
  • 2 and 3
  • 1, 2, and 3

Question 29

The increasing order of following functions in terms of asymptotic complexity is: [Tex]\\\\ f_{1}(n) = n^{0.999999}log (n)\\\\ f_{2}(n) = 10000000n\\\\ f_{3}(n) = 1.000001^{n} f_{4}(n) = n^{2} [/Tex]
  • f1(n); f4(n); f2(n); f3(n)
  • f1(n); f2(n); f3(n); f4(n);
  • f2(n); f1(n); f4(n); f3(n)
  • f1(n); f2(n); f4(n); f3(n)

Question 30

Consider the following C function.
 

C
int fun1 (int n)
{
   int i, j, k, p, q = 0;
   for (i = 1; i < n; ++i)
   {
      p = 0;
      for (j = n; j > 1; j = j/2)
         ++p;
      for (k = 1; k < p; k = k*2)
         ++q;
   }
   return q;
}

Which one of the following is the time complexity for function fun1?
 

  • n3
     

  • n (logn)2
     

  • nlogn 
     

  • nlog(logn)
     

There are 118 questions to complete.

Last Updated :
Take a part in the ongoing discussion