DAA MCQs Answer

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 17

MALLA REDDY ENGINEERING COLLEGE (AUTONOMOUS)

II B.Tech II Semester(MR 21) I Mid Question Bank AY 2022-23 (Objective)


Subject: Design and Analysis of Algorithms (B0516 ) Branch: CSE
Name of the Faculty: Dr. S.Sandhya Rani,
Mr. P V Ramana, Ms Asmitha p Ambekar

Module-I
1. Following is true for understanding of a problem D
A. Knowing the knowledgebase
B. Understanding the subject on which the problem is based
C. Communication with the client
D. All of the above
2. . ______is the first step in solving the problem B
A. Understanding the Problem
B. Identify the Problem
C. Evaluate the Solution
D. None of these
3. ______is the last step in solving the problem C
A. Understanding the Problem
B. Identify the Problem
C. Evaluate the Solution
D. None of these
4. The complexity of linear search algorithm is A
a. O(n)
b. O(log n)
c. O(n2)
d. O(n log n)

5. The complexity of Binary search algorithm is B


a. O(n)
b. O(log n )
c. O(n2)
d. O(n log n)

6. While solving the problem with computer the most difficult step is __________. C
A. describing the problem
B. finding out the cost of the software
C. writing the computer instructions
D. testing the solution
7. The correctness and appropriateness of ___________ can be checked very easily. A
A. algorithmic solution
B. heuristic solution
C. random solution
D. none of these

8. Finding the location of the element with a given value is: B


a. Traversal
b. Search
c. Sort
d. None of above
9. The main measure for efficiency algorithm are- D
A. Processor and Memory
B. Complexity and Capacity
C. Data and Space
D. Time and space
10. What does the algorithmic analysis count? A
A. The number of arithmetic and the operations that are required to run the
program
B. The number of lines required by the program
C. The number of seconds required by the program to execute
D. None of these
11. Examples of O(1) algorithms are______________. D
A. Multiplying two numbers.
B. assigning some value to a variable
C. displaying some integer on console
D. All of the above
12. Examples of O(n2) algorithms are______________. C
A. Adding of two Matrices
B. Initializing all elements of matrix by zero
C. Both A and B
D. Neither A nor B
13. There are four algorithms A1, A2, A3, A4 to solve the given problem with the C
order log(n), nlog(n), log(log(n))n/log(n), Which is the best algorithm.
A. A1
B. A2
C. A3
D. A4
14. Express the formula (n-1)*(n-5) in terms of big Oh notation D
A. O(1)
B. O(log n)
C. O(n)
D. O(n2)

15. The average time complexity of binary search is________. B


A. O(1)
B. O(log n)
C. O(n)
D. O(n logn)

16. The average time complexity of linear search is________. C


A. O(1)
B. O(log n)
C. O(n)
D. O(n logn)

17. In quick sort, the number of partitions into which the file of size n is divided by a C
selected record is
A. n
B. n – 1
C. 2
D. n/2
18. The running time of the following sorting algorithm depends on whether the B
partitioning balanced or unbalanced.
A. Insertion sort
B. Quick sort
C. Selection sort
D. Merge sort
19. The worst-case time complexity of Quick Sort is________. A
A. O(n2)
B. O(log n)
C. O(n)
D. O(n logn)
20. The worst-case time complexity of Merge Sort is________. B
A. O(n2)
B. O(log n)
C. O(n)
D. O(n logn)
21. The algorithm like Quick sort does not require extra memory for carrying out the A
sorting procedure. This technique is called __________.
A. in-place
B. stable
C. unstable
D. in-partition

22. Two main measures for the efficiency of an algorithm are C


A. Processor and memory
B. Complexity and capacity
C. Time and space
D. Data and space
23. The space factor when determining the efficiency of algorithm is measured by A
A. Counting the maximum memory needed by the algorithm
B. Counting the minimum memory needed by the algorithm
C. Counting the average memory needed by the algorithm
D. Counting the maximum disk space needed by the algorithm

24. The time factor when determining the efficiency of algorithm is measured by B
A. Counting microseconds
B. Counting the number of key operations
C. Counting the number of statements
D. Counting the kilobytes of algorithm

25. A list of n strings, each of length n, is sorted into lexicographic order using the A
merge-sort algorithm. The worst case running time of this computation is
A. O (n log n)
B. O (n2 log n)
C. O (n2 + log n)
D. O (n2)
26. Which of the following case does not exist in complexity theory? D
A. Best case
B. Worst case
C. Average case
D. Null case
27. The concept of order Big O is important because A
A. It can be used to decide the best algorithm that solves a given problem
B. It determines the maximum size of a problem that can be solved in a given
amount of time
C. It is the lower bound of the growth rate of algorithm
D. Both A and B
28. When determining the efficiency of algorithm, the space factor is measured by A
a. Counting the maximum memory needed by the algorithm
b. Counting the minimum memory needed by the algorithm
c. Counting the average memory needed by the algorithm
d. Counting the maximum disk space needed by the algorithm

29. Divide and Conquer uses ___ approach. A


A. Top-down
B. Bottom-up
C. Both (A) and (B)
D. Recursion
30. f(n)=Θ(g(n)) if and only if g(n)=Θ(f(n)) denotes_______ property. B
A. Transitivity
B. Symmetry
C. Transpose Symmetry
D. Reflexivity
31. In quick sort, the number of partitions into which the file of size n is divided by a C
selected record is
A. n
B. n – 1
C. 2
D. None of the above
32. The total number of comparisons made in quick sort for sorting a file of size n, is A
A. O(n log n)
B. O(n2)
C. n(log n)
D. None of the above
33. Quick sort efficiency can be improved by adopting A
A. non-recursive method
B. insertion method
C. tree search method
D. None of the above
34. For the improvement of efficiency of quick sort the pivot can be B
A. the first element
B. the mean element
C. the last element
D. None of the above
35. Quick sort is the fastest available method of sorting because of C
A. low over head
B. O(n log n) comparisons
C. low overhead and also O(n log n) comparisons
D. None of the above
36. In ______ Method sub problems are solved independently. B
A. Algorithm
B. Divide and Conquer
C. Greedy Method
D. Dynamic Programming
37. Suppose we need to sort a list of employee records in ascending order, using the D
social security number (a 9-digit number) as the key (i.e., sort the records by
social security number). If we need to guarantee that the running time will be no
worse than n log n, which sorting methods could we use?
A. mergesort
B. quicksort
C. insertion sort
D. Either mergesort or quicksort

38. Consider the following function f: D


int f(int n)
{
int s = 0;
while(n > 1)
{
n = n/2;
s++;
}
return s;
}
What is the asymptotic complexity in terms of n? (Pick the smallest correct
A. O(nlog n)
B. O(n)
C. O( n)
D. O(log n)
E. O(n^2 )

39. For merging two sorted lists of sizes m and n into a sorted list of size m n, requires C
________ number of comparisons.
A. O(m)
B. O(n)
C. O(m+n)
D. O(log m + log n)
40. The running time of the following sorting algorithm depends on whether the B
partitioning balanced or unbalanced.
A. Insertion sort
B. Quick sort
C. Selection sort
D. Merge sort
41. Which of the following is not a stable sorting algorithm in its typical C
implementation.
A Insertion Sort
B Merge Sort
C Quick Sort
D Bubble Sort
42. Which of the following method is taking overcharge for some operations in B
amortized analysis?
(A A. Aggregate method B. accounting method C. potential method
D. both (A) and (C)
43. Which of the following method is most flexible in amortized analysis? C
A. Aggregate method
B. accounting method
C. potential method
D. both (A) and (B)
44. Which of the following method is taken different operations different charges in B
amortized analysis?
A. Aggregate method
B. accounting method
C. potential method
D both (A) and (B)
45. Which of the following method is computing total cost of an algorithm in A
amortized analysis?
A. Aggregate method
B.accounting method
C. potential method
D. both (C) and (B)

46. Which of the following method is credit as the potential energy to pay for future C
operations?
A. Aggregate method
B. accounting method
C. potential method
D. both (A) and (B)
47. The time complexity of the normal quick sort, randomized quick sort algorithms B
in the worst case is
A. O(n2), O(n log n)
B. O(n2), O(n2)
C. O(n log n), O(n2)
D. O(n log n), O(n log n)
48. The Sorting method which is used for external sort is C
A. Bubble sort
B. Quick sort
C. Merge sort
D. Radix sort
49. In analysis of algorithm, approximate relationship between the size of the job and D
the amount of work required to do is expressed by using _________
A. Central tendency
B. Differential equation
C. Order of execution
D. Order of magnitude
50. If A is a matrix of order m x n and B is a matrix of order n x p then order of AB is D
A. pxm
B. pxn
C. nxp
D.m x p
Module-II
1. The disjoint set is an abstract data type that supports the operations, C
A. Union
B. Find
C. both A and B
D. none
2. A graph G is said to be ____________ if and only if it contains no articulation B
points.
A. Connected
B. Biconnected
C. either A or B
D. both A and B
3. If two sets A and B have no common elements i.e (A intersection B) has no C
element then such
sets are known as ?
a. Intersection
b. Union
c. Disjoint
d. Complemen

4. A graph is a collection of.... ? B


a. Row and columns
b. Vertices and edges
c. Equations
d. None of these

5. The degree of any vertex of graph is .... ? A


a. The number of edges incident with vertex
b. Number of vertex in a graph
c. Number of vertices adjacent to that vertex
d. Number of edges in a graph

6. Nodes which satisfy __________ , w being the children of u are identified as an A


articulation points.
A. L[w]≤dfn[u]
B. L[w]≥dfn[u]
C. dfn[u]≥L[w]
D. dfn[u]≤L[w]
7. A graph G is called a .....if it is a connected acyclic graph C
a. Cyclic graph
b. Regular graph
c. Tree
d. not a graph

8. An edge of a spanning tree is called a B


A. Chord
B. Branch
C. Vertex
D. Edge weight
9. Which of the following is not a type of graph ? D
a. Euler
b. Hamiltonian
c. Tree
d. Path

10. Heap is defined to be a A


A. complete binary tree
B. binary tree
C. tree structure
D. None of the above
a.
11. In a Max heap the largest key is at A
A. the root
B. a leaf
C. a node
D. None of the above

12. In heap sort the input is arranged in the form of a A


A. heap
B. tree
C. queue
D. None of the above

13. Heap sort is found to be very efficient A


A. with regard to storage requirement
B. in time consumption
C. regarding overheads involved
D. None of the above

14. What is the asymptotic runtime for traversing all nodes in a binary search tree B
with n nodes and printing them in order?
A. O(n ⋅ log(n))
B. O(n)
C. O( n)
D. O(log(n))
E. O(n^2 )
15. A minimal spanning tree of a graph G is.... ? D
a. A spanning sub graph
b. A tree
c. Minimum weights
d. All of above

16. The total running time of optimal binary search tree of n nodes C
(A) O(n2)
(B) O(n)
(C) O(n3)
(D) O(n log n)
17. A binary tree that has n leaf nodes. The number of nodes of degree 2 in this tree B
is ?
a. log2n
b. n - 1
c. n
d. 2n
18. The operation of processing each element in the list is known as ...... D
A. sorting
B. merging
C. inserting
D. traversal
19. Use the breadth first strategy to traverse the graph below A

List the vertices in the order in which breadth first search traverses them.

A. 1,4,5,3,2
B. 1,2,4,3,5
C. 1,3,5,4,2
D. 1,2,3,5,4
20. Which of the following algorithms can be used to most efficiently determine the A
presence of a cycle in a given graph ?
A Depth First Search
B Breadth First Search
C Prim’s Minimum Spanning Tree Algorithm
D Kruskal’ Minimum Spanning Tree Algorithm
21. Traversal of a graph is different from tree because A
A There can be a loop in graph so we must maintain a visited flag for every vertex
B DFS of a graph uses stack, but inorrder traversal of a tree is recursive
C BFS of a graph uses queue, but a time efficient BFS of a tree is recursive.
D All of the above
22. An undirected graph G(V, E) contains n ( n > 2 ) nodes named v1 , v2 ,….vn. Two B
nodes vi ,vj are connected if and only if 0 < |i – j| <= 2. Each edge (vi, vj ) is
assigned a weight i + j. A sample graph with n = 4 is shown below. What will be
the cost of the minimum spanning tree (MST) of such a graph with n nodes?P is
the number of predicate nodes contained in the flow graph G.
A. 1/12(11n^2 – 5n)
B. n^2 – n + 1
C. 6n – 11

D. 2n + 1

23. The length of the path from v5 to v6 in the MST of previous question with n = 10 C
is
A. 11
B. 25
C. 31
D. 41
24. Consider a complete undirected graph with vertex set {0, 1, 2, 3, 4}. Entry Wij in D
the matrix W below is the weight of the edge {i, j}. What is the minimum possible
weight of a spanning tree T in this graph such that vertex 0 is a leaf node in the
tree T?

A. 7 B. 8 C. 9 D. 10
25. In the graph given in above question, what is the minimum possible weight of a B
path P from vertex 1 to vertex 2 in this graph such that P contains at most 3 edges?
A. 7
B. 8
C. 9
D. 10
26. An undirected graph G has n nodes. Its adjacency matrix is given by an n × n C
square matrix whose (i) diagonal elements are 0‘s and (ii) non-diagonal elements
are 1‘s. which one of the following is TRUE?
(A) Graph G has no minimum spanning tree (MST)
(B) Graph G has a unique MST of cost n-1
(C) Graph G has multiple distinct MSTs, each of cost n-1
(D) Graph G has multiple spanning trees of different costs
27. Consider the following graph: D

Which one of the following cannot be the sequence of edges added, in that order,
to a minimum spanning tree using Kruskal’s algorithm?
(A) (a—b),(d—f),(b—f),(d—c),(d—e)
(B) (a—b),(d—f),(d—c),(b—f),(d—e)
(C) (d—f),(a—b),(d—c),(b—f),(d—e)
(D) (d—f),(a—b),(b—f),(d—e),(d—c)
28. The Breadth First Search algorithm has been implemented using the queue data C
structure. One possible order of visiting the nodes of the following graph is

(A) MNOPQR
(B) NQMPOR
(C) QMNPRO
(D) QMNPOR

29. In an unweighted, undirected connected graph, the shortest path from a node S to D
every other node is computed most efficiently, in terms of time complexity by
(A) Dijkstra’s algorithm starting from S.
(B) Warshall’s algorithm
(C) Performing a DFS starting from S.
(D) Performing a BFS starting from S.
30. Let G be an undirected connected graph with distinct edge weight. Let emax be C
the edge with maximum weight and emin the edge with minimum weight. Which
of the following statements is false?
(A) Every minimum spanning tree of G must contain emin
(B) If emax is in a minimum spanning tree, then its removal must disconnect G
(C) No minimum spanning tree contains emax
(D) G has a unique minimum spanning tree
31. Let G be an undirected graph. Consider a depth-first traversal of G, and let T be C
the resulting depth-first search tree. Let u be a vertex in G and let v be the first
new (unvisited) vertex visited after visiting u in the traversal. Which of the
following statements is always true? (GATE CS 2000)
(A) {u,v} must be an edge in G, and u is a descendant of v in T
(B) {u,v} must be an edge in G, and v is a descendant of u in T
(C) If {u,v} is not an edge in G then u is a leaf in T
(D) If {u,v} is not an edge in G then u and v must have the same parent in T
32. Consider a weighted complete graph G on the vertex set {v1,v2 ,v} such that the B
weight of the edge (v,,v) is 2|i-j|. The weight of a minimum spanning tree of G is:
(A) n—1
(B) 2n—2
(C) nC2
(D) 2
33. Consider the following graph D

Among the following sequences


I) a b e g h f
II) a b f e h g
III) a b f h g e
IV) a f g h b e
Which are depth first traversals of the above graph? (GATE CS 2003)
(A) I, II and IV only
(B) I and IV only
(C) II, III and IV only
(D) I, III and IV only
34. Other name for directed graph is .......... B
A. Direct graph
B. Digraph
C. Dir-graph
D. Digraph
35. In a weighted graph, assume that the shortest path from a source ‘s’ to a B
destination ‘t’ is correctly calculated using a shortest path algorithm. Is the
following statement true?
If we increase weight of every edge by 1, the shortest path always remains same.
(A) Yes
(B) No

36. Following statement is true or false? B


If we make following changes to Dijkstra, then it can be used to find the longest
simple path, assume that the graph is acyclic.
1) Initialize all distances as minus infinite instead of plus infinite.
2) Modify the relax condition in Dijkstra's algorithm to update distance of an
adjacent v of the currently considered vertex u only
if "dist[u]+graph[u][v] >dist[v]". In shortest path algo,
the sign is opposite.
(A) True
(B) False
37. The post order traversal of a binary tree is DEBFCA. Find out the pre order C
Traversal.
A. ABFCDE
B. ADBFEC
C. ABDECF
D. ABDCEF
38. Given two vertices in a graph s and t, which of the two traversals (BFS and DFS) C
can be used to find if there is path from s to t?
(A) Only BFS
(B) Only DFS
(C) Both BFS and DFS
(D) Neither BFS nor DFS
39. Which of the following condition is sufficient to detect cycle in a directed graph? B
(A) There is an edge from currently being visited node to an already visited node.
(B) There is an edge from currently being visited node to an ancestor of currently
visited node in DFS forest.
(C) Every node is seen twice in DFS.
(D) None of the bove
40. Is following statement true/false A
If a DFS of a directed graph contains a back edge, any other DFS of the same
graph will also contain at least one back edge.
(A) True
(B) False
41. Is following statement true/false? B
A DFS of a directed graph always produces the same number of tree edges, i.e.,
independent of the order in which vertices are considered for DFS.
(A) True
(B) False
42. If the DFS finishing time f[u] > f[v] for two vertices u and v in a directed graph G, B
and u and v are in the same DFS tree in the DFS forest, then u is an ancestor of v
in the depth first tree.
(A) True
(B) False
43. Is the following statement valid about shortest paths? A
Given a graph, suppose we have calculated shortest path from a source to all
other vertices. If we modify the graph such that weights of all edges is becomes
double of the original weight, then the shortest path remains same only the total
weight of path changes.
(A) True
(B) False
44. Is the following statement valid?. B
Given a weighted graph where weights of all edges are unique (no two edge have
same weights), there is always a unique shortest path from a source to destination
in such a graph.
(A) True
(B) False
45. In Binary trees nodes with no successor are called ...... B
A. End nodes
B. Terminal nodes
C. Final nodes
D. Last nodes
46. Which indicates pre-order traversal? C
A. Left sub-tree, Right sub-tree and root
B. Right sub-tree, Left sub-tree and root
C. Root, Left sub-tree, Right sub-tree
D. Right sub-tree, root, Left sub-tree
47. A terminal node in a binary tree is called ............ B
A. Root
B. Leaf
C. Child
D. Branch
48. In a graph if e=[u,v], Then u and v are called ........ D
A. End points of e
B. Adjacent nodes
C. Neighbours
D. All of the above
49. The in-order traversal of tree will yield a sorted listing of elements of tree in ........ B
A. binary trees
B. binary search trees
C. heaps
D. binary heaps

50. Three standards ways of traversing a binary tree T with root R ....... D
A. Prefix, infix, postfix
B. Pre-process, in-process, post-process
C. Pre-traversal, in-traversal, post-traversal
D. Pre-order, in-order, post-order
Module-III
.
Sl. Question Answer
No
1 Which of the following standard algorithms is not a Greedy algorithm? D
(A) Dijkstra’s shortest path algorithm
(B) Prim’s algorithm
(C) Kruskal algorithm
(D) Huffman Coding
2 Which of the following is true about Kruskal and Prim MST algorithms? Assume A
that Prim is implemented for adjacency list representation using Binary Heap and
Kruskal is implemented using union by rank.
(A) Worst case time complexity of both algorithms is same.
(B) Worst case time complexity of Kruskal is better than Prim
(C) Worst case time complexity of Prim is better than Kruskal
(D)none
3 If M=15, n=4, P=(10,10,12,18) and W=(2,4,6,9) of 0/1 knapsack problem then the D
maximum profit is
A. 32
B. 34
C. 36
D. 38

4 The greedy method and dynamic programming algorithm are the methods for D
obtaining ________solution.
A. Correct
B. Incorrect
C. Feasible
D. Optimum

5 which of the following technique is not using for solve a 0-1knapsack problem A

(A) Greedy
(B) Dynamic programming
(C) branch and bound
(D) all of the above
6 the total running time of matrix chain multiplication of n matrices B
(A) ϴ (n4) (B) ϴ (n3) (C) ϴ (n2) (D) ϴ (n)
7 the total running time of optimal binary search tree of n nodes C
(A) O(n2) (B) O(n)
(C) O(n3) (D) O(n log n)

8 If all c(i, j )’s and r(i, j)’s are calculated, then OBST algorithm in worst case takes B
one of the following time.
(a) O(n log n)
(b) O(n3)
(c) O(n2)
(d) O(log n)

9 Let A1, A2, A3, and A4 be four matrices of dimensions 10 x 5, 5 x 20, 20 x 10, and A
10 x 5, respectively. The minimum number of scalar multiplications required to find
the product A1A2A3A4 using the basic matrix multiplication method is
(A) 1500
(B) 2000
(C) 500
(D) 100
10 Four matrices M1, M2, M3 and M4 of dimensions pxq, qxr, rxs and sxt respectively C
can be multiplied is several ways with different number of total scalar
multiplications. For example, when multiplied as ((M1 X M2) X (M3 X M4)), the
total number of multiplications is pqr + rst + prt. When multiplied as (((M1 X M2)
X M3) X M4), the total number of scalar multiplications is pqr + prs + pst.
If p = 10, q = 100, r = 20, s = 5 and t = 80, then the number of scalar multiplications
needed is
(A) 248000
(B) 44000
(C) 19000
(D) 25000

11 The essence of greedy algorithm is the __________ policy. B


A) maximization
B) minimization
C) selection
D) either A or B
12 In Krushkal’s algorithm, the edges are selected and added to the spanning tree in A
_________order of their weights.
A) increasing
B) decreasing
C) increasing or decreasing
D) increasing and decreasing

13 The single-source shortest path problem has a good well known solution of the type_ B
A) Bruteforce
B) Greedy
C) DFS
D) Divide and conquer__
__.
14 The single-source shortest path problem is to find shortest paths from a source D
vertex to______________ in the graph.
A) Adjacent vertex
B) Nearest vertex
C) Same vertex
D) All other vertices

15 Single source shortest path takes _____ time. B

A) O(n)
B) O(n2)
C) O(2n)
D) O(logn)
16 The total running time of knapsack problem for a simple approach D
(A) O(n)
(B) O( log n)
(C) 2n logn)
(D) O(2n)

17 What is the time complexity of Bellman-Ford single-source shortest path algorithm C


on a completegraph of n vertices?
(A)Θ(n2)
(B)Θ(n2 Logn)
(C)Θ(n3)
(D) Θ(n3 Logn)

18 In dynamic programming, the output to stage n become the input to * C


(A). stage n-1
(B). stage n itself
(C). stage n+1
(D). stage n-2
19 Let G be a graph with ‘n’ nodes and let ‘m’ be the chromatic number of the graph. Then the
D
time taken by the backtracking algorithm to color it is
(a) O(nm)
(b) O(n+m)
(c) O(mnm)

(d) O(nmn).
20 The Knapsack problem where the objective function is to minimize the profit is D
______
(a) Greedy (b) Dynamic 0 / 1
(c) Back tracking (d) Branch & Bound 0/1

21 From the following algorithm design techniques which one is used to find all the C
pairs of shortest distances in a graph?

a. Backtracking
b. Greedy
c. Dynamic programming
d. Divide

22 Let A1, A2, A3, and A4 be four matrices of dimensions 10 x 5, 5 x 20, 20 x 10, and A
10 x 5, respectively. The minimum number of scalar multiplications required to find
the product A1A2A3A4 using the basic matrix multiplication method is
(A) 1500
(B) 2000
(C) 500
(D) 100
23 A path in graph G, which contains every vertex of G once and only once ? B
a. Eulartour
b. Hamiltonian Path
c. Eular trail
d. Hamiltonian tour

24 Which statement is true? B


(A) If a dynamic-programming problem satisfies the optimal-substructure property,
then a locally optimal solution is globally optimal
(B)If a greedy choice property satisfies the optimal-substructure property, then a
locally optimal solution is globally optimal
(C) Both of above
(D)None of above
25 In dynamic programming, the output to stage n become the input to * C
(A) stage n-1
(B) stage n itself
(C) stage n+1
(D) stage n-2

You might also like