• Last Updated : 23 Feb, 2022

 Question 1
Which of the following standard algorithms is not Dynamic Programming based.
 A Bellman–Ford Algorithm for single source shortest path B Floyd Warshall Algorithm for all pairs shortest paths C 0-1 Knapsack problem D Prim's Minimum Spanning Tree
Dynamic Programming    50 Algorithms MCQs with Answers
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?
 A The minimum possible time complexity of a comparison based sorting algorithm is O(nLogn) for a random input array B Any comparison based sorting algorithm can be made stable by using position as a criteria when two elements are compared C Counting Sort is not a comparison based sorting algorithm D Heap Sort is not a comparison based sorting algorithm.
Sorting    Analysis of Algorithms    CountingSort    HeapSort    50 Algorithms MCQs with Answers
Discuss it

Question 2 Explanation:
 Question 3
Which of the following is not O(n^2)?
 A (15^10) * n + 12099 B n^1.98 C n^3 / (sqrt(n)) D (2^20) * n
Analysis of Algorithms    50 Algorithms MCQs with Answers
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)
 A x + y using repeated subtraction B x mod y using repeated subtraction C the greatest common divisor of x and y D the least common multiple of x and y
Divide and Conquer    50 Algorithms MCQs with Answers
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?
 A Knight tour problem B N queen problem C Tower of hanoi D M coloring problem
Backtracking    50 Algorithms MCQs with Answers
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 A B B C C D D
Analysis of Algorithms (Recurrences)    50 Algorithms MCQs with Answers
Discuss it

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: (GATE CS 2005)
 A nk B (n – 1) k+ 1 C n( k – 1) + 1 D n( k – 1)
Algorithm Misc    50 Algorithms MCQs with Answers
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).
 A True B False
Analysis of Algorithms    50 Algorithms MCQs with Answers
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?
 A O(n^2logn) B Theta(n^2logn) C Theta(n^4) D Theta(n^3)
Analysis of Algorithms    50 Algorithms MCQs with Answers
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 A B B C C D D
NP Complete    50 Algorithms MCQs with Answers
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.
My Personal Notes arrow_drop_up