Top 50 Algorithms MCQs with Answers

The word Algorithm means “A set of rules to be followed in calculations or other problem-solving operations” Or “A procedure for solving a mathematical problem in a finite number of steps…
More on Algorithms…

Question 1

Which of the following standard algorithms is not Dynamic Programming based?

Cross

Bellman–Ford Algorithm for single source shortest path

Cross

Floyd Warshall Algorithm for all pairs shortest paths

Cross

0-1 Knapsack problem

Tick

Prim\'s Minimum Spanning Tree



Question 1-Explanation: 

Prim\'s Minimum Spanning Tree is a Greedy Algorithm. All others are dynamic programming based.

Hence (D) is the correct answer.

Question 2

Which of the following is not true about comparison-based sorting algorithms?

Cross

The minimum possible time complexity of a comparison-based sorting algorithm is O(n(log(n)) for a random input array

Cross

Any comparison based sorting algorithm can be made stable by using position as a criteria when two elements are compared

Cross

Counting Sort is not a comparison based sorting algorithm

Tick

Heap Sort is not a comparison based sorting algorithm.



Question 2-Explanation: 

Heap Sort is not a comparison based sorting algorithm is not correct.

Question 3

Which of the following is not O(n2)?

Cross

(15) * n2

Cross

n1.98

Tick

n3/(sqrt(n))

Cross

(20) * n2



Question 3-Explanation: 

The order of growth of option c is n2.5 which is higher than n2.

Question 4
Consider the following C program
int main() 
{ 
   int x, y, m, n; 
   scanf ("%d %d", &x, &y); 
   /* x > 0 and y > 0 */
   m = x; n = y; 
   while (m != n) 
   { 
      if(m>n) 
         m = m - n; 
      else
         n = n - m; 
   } 
   printf("%d", n); 
}
What does the program compute? (GATE CS 2004)
Cross
x + y using repeated subtraction
Cross
x mod y using repeated subtraction
Tick
the greatest common divisor of x and y
Cross
the least common multiple of x and y


Question 4-Explanation: 
This is an implementation of Euclid’s algorithm to find GCD
Question 5
Which of the following is not a backtracking algorithm?
Cross
Knight tour problem
Cross
N queen problem
Tick
Tower of hanoi
Cross
M coloring problem


Question 5-Explanation: 
Knight tour problem, N Queen problem and M coloring problem involve backtracking. Tower of hanoi uses simple recursion.
Question 6
Suppose T(n) = 2T(n/2) + n, T(0) = T(1) = 1 Which one of the following is false. ( GATE CS 2005)
a) T(n) = O(n^2)
b) T(n) = \\theta(nLogn)
c) T(n) = \\Omega(n^2)
d) T(n) = O(nLogn)
Cross
A
Cross
B
Tick
C
Cross
D


Question 6-Explanation: 
Question 7

In a complete k-ary tree, every internal node has exactly k children. The number of leaves in such a tree with n internal nodes is: 

Cross

nk

Cross

(n – 1) k+ 1

Tick

n( k – 1) + 1

Cross

n( k – 1)



Question 7-Explanation: 

For an k-ary tree where each node has k children or no children, following relation holds L = (k-1)*n + 1 Where L is the number of leaf nodes and n is the number of internal nodes. Let us see following for example

k = 3
Number of internal nodes n = 4
Number of leaf nodes = (k-1)*n  + 1
                     = (3-1)*4 + 1
                     = 9 

Question 8

The following statement is valid. log(n!) = \\theta (n log n).

Tick

True

Cross

False



Question 8-Explanation: 

Order of growth of \\log n! and n\\log n is the same for large values of , i.e.,  \\theta (\\log n!) = \\theta (n\\log n) . So time complexity of fun() is \\theta (n\\log n) . The expression \\theta (\\log n!) = \\theta (n\\log n) can be easily derived from following Stirling\'s approximation (or Stirling\'s formula). \\log n! = n\\log n - n +O(\\log(n))\\

Question 9

What is the time complexity of Floyd–Warshall algorithm to calculate all pair shortest path in a graph with n vertices?

Cross

O(n2log(n))

Cross

Theta(n2log(n))

Cross

Theta(n4)

Tick

Theta(n3)



Question 9-Explanation: 

Floyd–Warshall algorithm uses three nested loops to calculate all pairs shortest path. So, the time complexity is Theta(n3).
Please read here for more details.

Question 10

Assuming P != NP, which of the following is true ? 
(A) NP-complete = NP

(B) NP-complete \\cap P = \\Phi

(C) NP-hard = NP

(D) P = NP-complete
 

Cross

A

Tick

B

Cross

C

Cross

D



Question 10-Explanation: 

The answer is B (no NP-Complete problem can be solved in polynomial time). Because, if one NP-Complete problem can be solved in polynomial time, then all NP problems can solved in polynomial time. If that is the case, then NP and P set become same which contradicts the given condition.

Hence (B) is the correct answer.

There are 50 questions to complete.


  • Last Updated : 26 Sep, 2023

Share your thoughts in the comments
Similar Reads