• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top MCQs on Complexity Analysis of Algorithms with Answers

Question 11

Consider the following functions

  • f(n) = 3n^{\sqrt{n}}
  • g(n) = 2^{\sqrt{n}{\log_{2}n}}
  • h(n) = n!

Which of the following is true? (GATE CS 2000)
(A) h(n) is 0(f(n))
(B) h(n) is 0(g(n))
(C) g(n) is not 0(f(n))
(D) f(n) is 0(g(n))

  • A

  • B

  • C

  • D

Question 12

Consider the following three claims:

I [Tex](n + k)^m = \theta(n^m)[/Tex] where k and m are constants

II [Tex]2^{n+1} = O(2^n)   [/Tex] 

 III 2^{2n+1} = O(2^n)

Which of these claims is correct? (GATE CS 2003)

  • I and II

  • I and III

  • II and III

  • I, II and III

Question 13

Let s be a sorted array of n integers. Let t(n) denote the time taken for the most efficient algorithm to determined if there are two elements with sum less than 1000 in s. which of the following statements is true? (GATE CS 2000)
a) t (n) is 0 (1)
b) n < t (n) < n[Tex] {log_2 n} [/Tex]
c) n log 2 n < t (n) < [Tex]{n \\choose 2} [/Tex]
d) t (n) = [Tex]{n \\choose 2} [/Tex]

  • a

  • b

  • c

  • d

Question 14

Consider the following function,

 int unknown(int n) {
    int i, j, k = 0;
    for (i  = n/2; i <= n; i++)
        for (j = 2; j <= n; j = j * 2)
            k = k + n/2;
    return k;
 }

What is the time complexity of the function? (GATE CS 2013)

  • n^2

  • n logn

  • n^3

  • n^3 logn 

Question 15

Consider the following two functions. What are time complexities of the functions? 

C
int fun1(int n)
{
    if (n <= 1) return n;
    return 2*fun1(n-1);
}
C
int fun2(int n)
{
    if (n <= 1) return n;
    return fun2(n-1) + fun2(n-1);
}
  • O(2^n) for both fun1() and fun2()

  • O(n) for fun1() and O(2^n) for fun2()

  • O(2^n) for fun1() and O(n) for fun2()

  • O(n) for both fun1() and fun2()

Question 16

What is the worst case time complexity of insertion sort where position of the data to be inserted is calculated using binary search?

  • N

  • N*log(N)

  • N2

  • N*log(N)2

Question 17

The tightest lower bound on the number of comparisons, in the worst case, for comparison-based sorting is of the order of
  • N
  • N^2
  • NlogN
  • N(logN)^2

Question 18

The number of elements that can be sorted in [Tex]\\Theta(logn)[/Tex] time using heap sort is
(A) [Tex]\\Theta(1)[/Tex]
(B) [Tex]\\Theta(\\sqrt{logn})[/Tex]
(C) [Tex]\\Theta(Log n/(Log Log n))[/Tex]
(d) [Tex]\\Theta(Log n)[/Tex] 
  • A
  • B
  • C
  • D

Question 19

Consider the following segment of C-code:
  int j, n;
  j = 1;
  while (j <= n)
        j = j*2; 
The number of comparisons made in the execution of the loop for any n > 0 is: Base of Log is 2 in all options.
  • CEIL(logn) + 2
  • n
  • CEIL(logn)
  • FLOOR(logn) + 2

Question 20

Consider the following C-program fragment in which i, j and n are integer variables. C
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? (A) val(j) = [Tex]\\theta[/Tex](logn) (B) vaI(j) = [Tex]\\theta[/Tex](sqrt(n)) (C) val(j) = [Tex]\\theta[/Tex](n) (D) val(j) = [Tex]\\theta[/Tex](nlogn)
  • A
  • B
  • C
  • D

There are 118 questions to complete.

Last Updated :
Take a part in the ongoing discussion