Professional Documents
Culture Documents
DAA QB
DAA QB
TIRUCHIRAPPALLI
2. If an optimal solution can be created for a problem by constructing optimal solutions for its
subproblems, the problem possesses ____________ property.
a)Overlapping subproblems
b)Optimal substructure
c)Memoization
d)Greedy
3.If a problem can be solved by combining optimal solutions to non-overlapping problems, the
strategy is called _____________
a)Dynamic programming
b)Greedy
c)Divide and conquer
d)Recursion
12)Fractional knapsack problem is solved most efficiently by which of the following algorithm?
a)Backtracking
b)Greedy algorithm
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI
13. 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
14.Consider the two matrices P and Q which are 10 x 20 and 20 x 30 matrices respectively. What
is the number of multiplications required to multiply the two matrices?
a)10*20
b)20*30
c)10*30
d)10*20*30
21.Which of the following is an example of a problem that can be solved using backtracking?
(A) Finding the median of an array
(B) Binary search in a sorted list
(C) Sudoku puzzle solving
(D) Calculating the sum of elements in an array
Answer (C)
26. How does the practical travelling salesman problem differ from the classical travelling
salesman problem?
a) In the practical travelling salesman problem each vertex can only be visited once
b) In the practical travelling salesman problem each vertex can be visited more than once
c) In the practical travelling salesman problem each edge can only be visited once
d) In the practical travelling salesman problem each edge can be visited more than once
27. Which of the following is false in the case of a spanning tree of a graph G?
a) It is tree that spans G
b) It is a subgraph of the G
c) It includes every vertex of the G
d) It can be either cyclic or acyclic
Answer: d
28. Consider a complete graph G with 4 vertices. The graph G has ____ spanning trees.
a) 15
b) 8
c) 16
d) 13
30. Consider the following graph. Using Kruskal’s algorithm, which edge will be selected first?
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI
a) GF
b) DE
c) BE
d) BG
Answer: c
31. Which of the following edges form minimum spanning tree on the graph using kruskals
algorithm?
a) (B-E)(G-E)(E-F)(D-F)
b) (B-E)(G-E)(E-F)(B-G)(D-F)
c) (B-E)(G-E)(E-F)(D-E)
d) (B-E)(G-E)(E-F)(D-F)(D-G)
Answer: a
33. Worst case is the worst case time complexity of Prim’s algorithm if adjacency matrix is
used?
a) O(log V)
b) O(V2)
c) O(E2)
d) O(V log E)
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI
39. 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
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI
43. What is the worst case running time of Rabin Karp Algorithm?
a) Theta(n)
b) Theta(n-m)
c) Theta((n-m+1)m)
d) Theta(nlogm)
Answer: c
45. Problems that can be solved in polynomial time are known as?
a) intractable
b) tractable
c) decision
d) complete
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI
46. _________ is the class of decision problems that can be solved by non-deterministic
polynomial algorithms.
a) NP
b) P
c) Hard
d) Complete
Answer: a
51. Which of the following problems is similar to that of a Hamiltonian path problem?
a) knapsack problem
b) closest pair problem
c) travelling salesman problem
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI
52. In what time can the Hamiltonian path problem can be solved using dynamic programming?
a) O(N)
b) O(N log N)
c) O(N2)
d) O(N2 2N)
Answer: d
53. What is the worst case time complexity of dynamic programming solution of the subset sum
problem(sum=given subset sum)?
a) O(n)
b) O(sum)
c) O(n2)
d) O(sum*n)
Answer: d
54. Vertex covering can be a good approach to which type of the problems?
a) Where all the vertex in the graph need to be included
b) Where all the edges in the graph need to be included
c) Only half edges in the graph need to be included
d) Only half of the total vertices need to be included
Answer: b
55. The greedy algorithm can find a minimal vertex cover in polynomial time for which among
the following?
a) Tree graphs
b) Bipartite graphs
c) Hypercube
d) Clique graphs
Answer: b
56. Which among the following problem uses the vertex cover approach?
a) Traveling salesperson problem
b) Assignment problem
c) Activity selection problem
d) Knapsack problem
Answer: a
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI
1. Fill up the Knapsack using Branch and bound technique and find the optimal solution.
Item 1 2 3 4
Profit 10 10 12 18
Weight 2 4 6 9
Capacity of Knapsack, M=15.
2. Fill up the Knapsack using Branch and bound technique and find the optimal solution.
Item 1 2 3 4
Profit 10 10 14 18
Weight 2 4 5 9
Capacity of Knapsack, M=11.
3. Construct a optimal minimum spanning tree using Kruskal’s algorithm for the given tree.
4. Construct a optimal minimum spanning tree using Prim’s algorithm for the given tree.
5. Find out the variable length code for a given input characters and frequency of characters
using Huffmann code. Calculate the Message and table size.
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI
6. Find out the variable length code for a given input characters and frequency of characters
using Huffmann code. Calculate the Message and table size.
Character A B C D E
Count/Freq 2 3 7 4 2
7. Find the Longest common subsequence for the given input using Dynamic programming.
A a B D a c e
B b A B c e
8. Find the Longest common subsequence for the given input using Dynamic programming.
A g R E a T e
B r D A t G
9. Fill up the Knapsack using Dynamic programming and find the optimal solution.
Item 1 2 3 4
Profit 1 2 5 6
Weight 2 3 4 5
Capacity of Knapsack, M=8.
10. Fill up the Knapsack using greedy technique based on ratio of profit to weight and find the
optimal solution.
Item 1 2 3
Profit 24 20 16
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI
12 Mark Questions
1. Solve a travelling sales person problem using dynamic programming
2. Write a function to compute lengths of shortest paths between all pairs of nodes for the given
adjacency matrix.
18. Discuss Rabin karp algorithm for string matching with suitable examples and analyse its time
complexity.
19. Solve a travelling sales person problem using dynamic programming
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI