50 Algorithms MCQs with Answers
Question 1 |
Which of the following standard algorithms is not Dynamic Programming based.
Bellman–Ford Algorithm for single source shortest path | |
Floyd Warshall Algorithm for all pairs shortest paths | |
0-1 Knapsack problem | |
Prim's Minimum Spanning Tree |
Discuss it
Question 1 Explanation:
Prim's Minimum Spanning Tree is a Greedy Algorithm. All other are dynamic programming based.
Question 2 |
Which of the following is not true about comparison based sorting algorithms?
The minimum possible time complexity of a comparison based sorting algorithm is O(nLogn) for a random input array | |
Any comparison based sorting algorithm can be made stable by using position as a criteria when two elements are compared | |
Counting Sort is not a comparison based sorting algorithm | |
Heap Sort is not a comparison based sorting algorithm. |
Discuss it
Question 2 Explanation:
See http://www.geeksforgeeks.org/lower-bound-on-comparison-based-sorting-algorithms/ for point A. See http://www.geeksforgeeks.org/stability-in-sorting-algorithms/ for B. C is true, count sort is an Integer Sorting algorithm.
Question 3 |
Which of the following is not O(n^2)?
(15^10) * n + 12099 | |
n^1.98 | |
n^3 / (sqrt(n)) | |
(2^20) * n |
Discuss it
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)
x + y using repeated subtraction | |
x mod y using repeated subtraction | |
the greatest common divisor of x and y | |
the least common multiple of x and y
|
Discuss it
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?
Knight tour problem | |
N queen problem | |
Tower of hanoi | |
M coloring problem |
Discuss it
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) =
(nLogn)
c) T(n) =
(n^2)
d) T(n) = O(nLogn)
a) T(n) = O(n^2)
b) T(n) =

c) T(n) =

d) T(n) = O(nLogn)
A | |
B | |
C | |
D |
Discuss it
Question 6 Explanation:
See question 4 of http://www.geeksforgeeks.org/data-structures-and-algorithms-set-23/ for 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: (GATE CS 2005)
nk | |
(n – 1) k+ 1 | |
n( k – 1) + 1 | |
n( k – 1) |
Discuss it
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
o / | \ o o o / | \ / | \ o o o o o o / | \ o o o 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!) =
(n log n).

True | |
False |
Discuss it
Question 8 Explanation:
Order of growth of
and
is same for large values of
, i.e.,
. So time complexity of fun() is
.
The expression
can be easily derived from following Stirling's approximation (or Stirling's formula).








Question 9 |
What is the time complexity of Floyd–Warshall algorithm to calculate all pair shortest path in a graph with n vertices?
O(n^2logn) | |
Theta(n^2logn) | |
Theta(n^4) | |
Theta(n^3) |
Discuss it
Question 9 Explanation:
Floyd–Warshall algorithm uses three nested loops to calculate all pair shortest path. So, time complexity is Thete(n^3). Read here for more details.
Question 10 |
Assuming P != NP, which of the following is true ?
(A) NP-complete = NP
(B) NP-complete
P =
(C) NP-hard = NP
(D) P = NP-complete
(A) NP-complete = NP
(B) NP-complete


(C) NP-hard = NP
(D) P = NP-complete
A | |
B | |
C | |
D |
Discuss it
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.
There are 50 questions to complete.