• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top MCQs on Complexity Analysis of Algorithms with Answers

Question 1

What is time complexity of fun()? 

C
int fun(int n)
{
    int count = 0;
    for (int i = n; i > 0; i /= 2)
        for (int j = 0; j < i; j++)
            count += 1;
    return count;
}
  • O(n2)

  • O(n*log(n))

  • O(n)

  • O(n*log(n*Log(n)))

Question 2

What is the time complexity of fun()? 

C
int fun(int n)
{
    int count = 0;
    for (int i = 0; i < n; i++)
        for (int j = i; j > 0; j--)
            count = count + 1;
    return count;
}
  • Theta (n)

  • Theta (n2)

  • Theta (n*log(n))

  • Theta (n*(log(n*log(n))))

Question 3

The recurrence relation capturing the optimal time of the Tower of Hanoi problem with n discs is. (GATE CS 2012)

  • T(n) = 2T(n – 2) + 2

  • T(n) = 2T(n – 1) + n

  • T(n) = 2T(n/2) + 1

  • T(n) = 2T(n – 1) + 1

Question 4

O( n2 ) is the worst case time complexity, so among the given options it can represent :-

  • O( n )

  • O( 1 )

  • O ( nlogn )

  • All of the above

Question 5

Which of the given options provides the increasing order of asymptotic complexity of functions f1, f2, f3, and f4?

  f1(n) = 2n
  f2(n) = n(3/2)
  f3(n) = n*log(n)
  f4(n) = nlog(n)
  • f3, f2, f4, f1

  • f3, f2, f1, f4

  • f2, f3, f1, f4

  • f2, f3, f4, f1

Question 6

What is the time complexity of the below function? 

C
void fun(int n, int arr[])
{
    int i = 0, j = 0;
    for (; i < n; ++i)
        while (j < n && arr[i] < arr[j])
            j++;
}
  • O(n)

  • O(n2)

  • O(n*log(n))

  • O(n*log(n)2)

Question 7

In a competition, four different functions are observed. All the functions use a single for loop and within the for loop, same set of statements are executed. Consider the following for loops: 

C
A) for(i = 0; i < n; i++)

B) for(i = 0; i < n; i += 2)

C) for(i = 1; i < n; i *= 2)

D) for(i = n; i <= n; i /= 2)

If n is the size of input(positive), which function is most efficient(if the task to be performed is not an issue)?

  • A

  • B

  • C

  • D

Question 8

What does it mean when we say that an algorithm X is asymptotically more efficient than Y?

  • X will be a better choice for all inputs

  • X will be a better choice for all inputs except possibly small inputs

  • X will be a better choice for all inputs except possibly large inputs

  • Y will be a better choice for small inputs

Question 9

Consider the following functions:

  f(n)   = 2n
  g(n)   = n!
  h(n)   = nlog(n)

Which of the following statements about the asymptotic behavior of f(n), g(n), and h(n) is true?
(A) f(n) = O(g(n)); g(n) = O(h(n))
(B) f(n) = [Tex]\\Omega  [/Tex](g(n)); g(n) = O(h(n))
(C) g(n) = O(f(n)); h(n) = O(f(n))
(D) h(n) = O(f(n)); g(n) = [Tex]\\Omega  [/Tex](f(n))

  • A

  • B

  • C

  • D

Question 10

In the following C function, let n >= m. 

C
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?
(A) [Tex]\\theta  [/Tex](log(n))
(B) [Tex]\\Omega  [/Tex](n)
(C) [Tex]\\theta  [/Tex](log(log(n)))
(D) [Tex]\\theta  [/Tex](sqrt(n))

  • A

  • B

  • C

  • D

There are 118 questions to complete.

Last Updated :
Take a part in the ongoing discussion