Advanced Algorithms MCQ
Advanced Algorithms MCQ
7. Breadth First Search uses ________ as an auxiliary structure to hold nodes for future
processing.
a) Stack
b) Linked List
c) Graph
d) Queue
Ans: c)
8. Quick sort is based on Divide and conquer paradigm. We divide the problem on the basis
of pivot element and
a) There is explicit combine process as well to conquer the solution.
b) No work is needed to combine the sub-arrays, the arrays is already sorted.
c) Merging the subarrays
d) Splitting the subarrays
Ans: a)
9. Dijkstra’s Algorithm is used to solve _____________ problems.
a) All pair shortest path
b) Single source shortest path
c) Network flow
d) Sorting
Ans. b)
10. Which of the following statement about 0/1 knapsack and fractional knapsack problem is
correct?
a) In 0/1 knapsack problem items are divisible and in fractional knapsack items are
indivisible
b) Both are the same
c) 0/1 knapsack is solved using a greedy algorithm and fractional knapsack is solved using
dynamic programming
d) In 0/1 knapsack problem items are indivisible and in fractional knapsack items are
divisible
Ans. d)
Ans. c)
Select the appropriate recursive call for QuickSort.(arr is the array, low is the starting index
13)
and high is the ending index of the array, partition returns the pivot element, we will see the
code for partition very soon)
a)
public static void quickSort(int[] arr, int low, int high)
{
int pivot;
if(high>low)
{
pivot = partition(arr, low, high);
quickSort(arr, low, pivot-1);
quickSort(arr, pivot+1, high);
}
}
b)
public static void quickSort(int[] arr, int low, int high)
{
int pivot;
if(high<low)
{
pivot = partition(arr, low, high);
quickSort(arr, low, pivot-1);
quickSort(arr, pivot+1, high);
}
}
c)
public static void quickSort(int[] arr, int low, int high)
{
int pivot;
if(high>low)
{
pivot = partition(arr, low, high);
quickSort(arr, low, pivot);
quickSort(arr, pivot, high);
}
}
d)
public static void quickSort(int[] arr, int low, int high)
{
int pivot;
if(high>low)
{
pivot = partition(arr, low, high);
quickSort(arr, low, pivot);
quickSort(arr, pivot+2, high);
}
}
Ans. a)
15. The number of scalar additions and subtractions used in Strassen’s matrix multiplication
algorithm is ________
a) O(n2.81)
b) Theta(n2)
c) Theta(n)
d) O(n3)
Ans. b)
16. Naive matrix multiplication of two N×N matrices has running time
A. Θ(N).
B. Θ(N2).
C. Θ(N3).
D. Θ(1).
Ans. c)
17. Divide and conquer consists of
A. Divide and Combine
B. Divide,Conquer and Combine
C. Divide and Conquer
D. None of the above
Ans. b)
18. The LU decomposition is
a) The name of an algorithm to solve a linear system.
b) A matrix decomposition which writes a matrix as the product of a lower triangular matrix
and an upper triangular matrix.
c) The same as a QR decomposition.
d) system to solve linear congruences\
Ans. b)
19. Any matrix can be factorized to LU form without pivoting.
a) Yes
b) No
c) Cannot say
d) Data not sufficient
ans. b)
a) -det(L)*det(U)
b) ( l11 * l22 *...* lnn) * (u11*u22*...*unn )
c) ( l12 * l23 *...* lnn+1) * (u12*u23*...*unn+1 )
d) None of those
Ans: b)
21. In Breadth First Search, if the vertex is encountered the first time during the search, it is
said to be _____________
a) entered
b) finished
c) discovered
d) Undiscovered
Ans. c)
22.
For a graph G = (V, E) with source s, the predecessor subgraph of G is G = (V , E) where
a) V ={vV : [v] NIL}{s} and E ={([v],v)E : v V - {s}}
b) V ={vV : [v] = NIL}{s} and E ={([v],v)E : v V }
c) V ={vV : [v] NIL} and E ={([v],v)E : v V - {s}}
d) V ={vV : [v] = NIL} and E ={([v],v)E : v V - {s}}
Ans: a)
23. Which application of stack is used to ensure that the pair of parentheses is properly
nested?
a) Balancing symbols
b) Reversing a stack
c) Conversion of an infix to postfix expression
d) Conversion of an infix to prefix expression
Ans. a)
24. You are driving alone from Virginia Beach to Los Angeles in a Porsche 911 Carrera on a
fixed 2800 mile route. Assume that you can go 250 miles on one tank of gas and that you
have a map showing every gas station on the route. What methodology for designing efficient
algorithms would you choose to determine which gas stations to stop at and how much gas to
get at each station?
Ans. b)
Ans. c)
28. You are given a knapsack that can carry a maximum weight of 60. There are 4 items with
weights {20, 30, 40, 70} and values {70, 80, 90, 200}. What is the maximum value of the
items you can carry using the knapsack?
a) 160
b) 200
c) 170
d) 90
Ans. a)
29. What is the time complexity of the brute force algorithm used to solve the optimal
parenthesization of matrix chain multiplication?
a) O(n2)
b) O(4n / n3/2)
c) O(2n / n)
d) O(n3)
Ans. b)
30. If a problem can be broken into subproblems which are reused several times, the problem
possesses ____________ property.
a) Overlapping subproblems
b) Optimal substructure
c) Memoization
d) Greedy
Ans: (a)
31. If same subproblem is solved several times, we can use ________ to store result of a
subproblem the first time it is computed and thus never have to recompute it again.
a) table
b) list
c) stack
d) queue
Ans: a)
Ans. A
Ans: a)
35. NP is the class of decision problems that can be solved by ____________ algorithms.
a) deterministic polynomial
b) non-deterministic polynomial
c) deterministic exponential
d) non-deterministic exponential
Ans. b)
36. The objective function for a L.P model is 3𝑥1 + 2𝑥2, if 𝑥1 = 20 and 𝑥2 = 30, what is the
value of the objective function?
A) 0
B) 50
C) 60
D) 120
Ans: D
37. The linear function of the variables which is to be maximize or minimize is called
A) Constraints
B) Objective function
C) Decision variable
D) None of the above
Ans. B)
Ans. D
41. What is also defined as the non‐negative variables which are added in the LHS of the
constraint to convert the inequality ‘< ‘ into an equation?
a) Slack variables
b) Simplex algorithm
c) Key element
d) surplus variables
Ans . a)
Ans. A
(10,120)
(120,10)
(30,100)
(60,90)
Ans. C
45. In simplex method, the feasible basic solution must satisfy the
negativity constraint
non-negativity constraint
basic constraint
common constraint
Ans: B
48. A ___________ graph is a subgraph of a graph where there are no edges adjacent to each
other.
a. maximal matching
b. matching
c. maximum matching
d. perfect
Ans. b)