100% found this document useful (1 vote)
4K views

Advanced Algorithms MCQ

The document discusses various algorithms and data structures concepts. It includes questions about insertion sort, quicksort, Dijkstra's algorithm, topological sort, breadth-first search, and their time complexities. Questions also cover graph traversal algorithms like BFS, graph representations, matrix operations, string matching, knapsack problems, and NP-completeness.

Uploaded by

mathu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
4K views

Advanced Algorithms MCQ

The document discusses various algorithms and data structures concepts. It includes questions about insertion sort, quicksort, Dijkstra's algorithm, topological sort, breadth-first search, and their time complexities. Questions also cover graph traversal algorithms like BFS, graph representations, matrix operations, string matching, knapsack problems, and NP-completeness.

Uploaded by

mathu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

ADVANCED ALGORITHMS

1. Which of the following is correct with regard to insertion sort?


a. insertion sort is stable and it sorts In-place
b. insertion sort is unstable and it sorts In-place
c. insertion sort is stable and it does not sort In-place
d. insertion sort is unstable and it does not sort In-place
Ans: a)
2. Insertion sort could be proved formally with a loop invariant, where ___________ part of
the proof states that if it's true before an iteration of a loop, it remains true before the next
iteration.
a) initialization
b) maintenance
c) termination
d) initialization and maintenance
Ans. b)
3. What is the worst case time complexity of a quick sort algorithm on an input array of N
numbers?
a) Θ(N)
b) Θ (N log N)
c) Θ (N2)
d) Θ (log N)
Ans. c)
4. Which of the following algorithm can be used to efficiently calculate single source shortest
paths in a Directed Acyclic Graph?
a) Dijkstra
b) Bellman-Ford
c) Topological Sort
d) Strongly Connected Component
Ans: c)
5. How long does breadth-first search take for a graph with vertex set V and edge set E?
a) O(V+E)
b) O(V)
c) O(V2)
d) O(V-E)
Ans: a)
6. O(1) represents that the computing time is _________.
a) Constant
b) Quadratic
c) Linear
d) Cubic
Ans: a)

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)

11) Which of the following statements is true?


a) We can add as many edges as we would like to a maximum matching and still have a
matching.
b) A matching of a graph is a set of edges from the graph such that no two edges share a
vertex.
c) A graph can only have one maximum matching.
d) A matching of a graph is a set of vertices from the graph such that no two vertices share an
edge
Ans. b)
12) In Activity-Selection problem, each activity i has a start time si and a finish time fi where
si≤fi. Activities i and j are compatible if:
a. si≥fj
b. sj≥fi
c. si≥fj or sj≥fi
d. si≥fj and sj≥fi

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)

14) Strassen’s algorithm is a/an_____________ algorithm.


a) Non- recursive
b) Recursive
c) Approximation
d) Accurate
Ans.b)

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)

20. If A = LU then, det(a) equals:

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 ={vV : [v]  NIL}{s} and E ={([v],v)E : v  V - {s}}
b) V ={vV : [v] = NIL}{s} and E ={([v],v)E : v  V }
c) V ={vV : [v]  NIL} and E ={([v],v)E : v  V - {s}}
d) V ={vV : [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)

23. Define the function T(n) by the following recurrence:


T(n) = 3T(n/4) + n2.5 . What is the easiest method to solve this recurrence asymptotically?
a. Master Theorem
b. Evaluate the summation
c. Recursion tree
d. Parenthesis Theorem
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?

a. Divide and conquer


b. Greedy
c. Dynamic programming
d. Linear Programming
Ans: b)

25. Which of the following decision problems is not NP-complete?


a. Hamiltonian Path
b. Shortest Path
c. 3-CNF Satisfiability
d. Set Cover
Ans : b)
26. What happens when the value of k is 0 in the Floyd Warshall Algorithm?
A. 1 intermediate vertex
B. 0 intermediate vertex
C. N intermediate vertices
D. N-1 intermediate vertices

Ans. b)

27) A product of matrices is _____________if it is either a single matrix or the product of


two fully parenthesized matrix products, surrounded by parentheses.
a) parenthesized
b) completely parenthesized
c) fully parenthesized
d) partially parenthesized

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)

32. If a ≡ b mod n , then

a) a and b leave the same nonnegative remainder when divided by n.


b) a and b leave the different nonnegative remainder when divided by n.
c) a and b need not leave the same nonnegative remainder when divided by n
d) none of the above

Ans. A

33. Solve the system of linear congruences


x ≡ 1 (mod 5)
x ≡ 2 (mod 7)
x ≡ 3 (mod 9)
x ≡ 4 (mod 11).

Find the value of M1, M2, M3 and M4.


a) M1=693, M2=495, M3=385, M4=315
b) M1=690, M2=495, M3=315, M4=385
c) M1=695, M2=490, M3=385, M4=315
d) M1=693, M2=395, M3=384, M4=385
Ans. a)
34. Choose the correct answer for the following statements:
I. The theory of NP-completeness provides a method of obtaining a polynomial time for NP
algorithms.
II. All NP complete problem are Np-hard
a) I is false and II is true
b) I is true and II is false
c) Both are true
d) Both are false

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)

38. The first step in formulating a linear programming problem is


A) Identify any upper or lower bound on the decision variables
B) State the constraints as linear combinations of the decision variables
C) Understand the problem
D) Identify the decision variables

Ans. D

39. A solution which optimizes the objective function is called as ------


A. Solution
B. Basic Solution
C. Feasible solution
D. Optimal solution
Ans. D

40. ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ are expressed is n the form of inequalities or equations


a) Constraints
b) Objective Functions
c) Both A and B
d) Neither A nor B
Ans. a)

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)

42. When an algorithm achieves an approximation ratio of ϱ (n), we call it a ___________


ϱ (n) -approximation algorithm
ϵ- approximation algorithm
ϵ+1 approximation algorithm
ϱ (n+1) approximation algorithm
Ans. a)
43. The difference between the left-hand side and right-hand side of a less-than-or-equal-to
constraint is referred to as
slack.
surplus.
constraint.
shadow price.

Ans. A

44. Consider the following linear programming problem:


Maximize 12X + 10Y
Subject to: 4X + 3Y ≤ 480
2X + 3Y ≤ 360
all variables ≥ 0
Which of the following points (X,Y) is feasible?

(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

46. Interpolation determines coefficient form of polynomial from _______


vector representation
point-value representation
coefficient representation
degree-bound representation
Ans b)

47. Which of the following is not a polynomial time algorithm?


Insertion sort
Merge Sort
Matrix Multiplication
Travelling Salesman Problem
Ans. d)

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)

49. A _________ is one to which no additional edge can be added.


a) Perfect matching
b) Maximal matching
c) Maximum matching
d) graph matching
Ans. b)
50. Any integer strictly greater than the degree of a polynomial is a ___________ of that
polynomial.
a. coefficient
b. degree-bound
c. convolution
d. interpolation
Ans. b)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy