You are on page 1of 16

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

TIRUCHIRAPPALLI

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing

Course Code & Title: 21CSC204J , Design and Analysis of Algorithms


Question Bank (UNIT 3,4,5)

Multiple Choice Questions


1. Which of the following is/are property/properties of a dynamic programming problem?
a)Optimal substructure
b)Overlapping subproblems
c)Greedy approach
d)Both optimal substructure and overlapping subproblems

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

4.When a top-down approach of dynamic programming is applied to a problem, it usually


_____________
a)Decreases both, the time complexity and the space complexity
b)Decreases the time complexity and increases the space complexity
c)Increases the time complexity and decreases the space complexity
d)Increases both, the time complexity and the space complexity

5. 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
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing
6. Which of the following problems should be solved using dynamic programming?
a)Merge sort
b)Binary search
c)Longest common subsequence
d)Quicksort

7. Dijkstra’s Algorithm is the prime example for ___________


a)Dynamic programming
b)Back tracking
c)Branch and bound
d)Greedy algorithm

8. Which of the following is false about the Kruskal’s algorithm?


a)It constructs MST by selecting edges in increasing order of their weights
b)It is a greedy algorithm
c)It uses union-find data structure
d)It can accept cycles in the MST

9.Fractional knapsack problem is also known as __________


a)0/1 knapsack problem
b)Continuous knapsack problem
c)Divisible knapsack problem
d)Non continuous knapsack problem

10. What is the objective of the knapsack problem?


a)To get maximum total value in the knapsack
b)To get minimum total value in the knapsack
c)To get maximum weight in the knapsack
d)To get minimum weight in the knapsack

11)Time complexity of fractional knapsack problem is ____________


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

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

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing
c)Dynamic programming
d)Divide and conquer

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

15.Consider the matrices P, Q and R which are 10 x 20, 20 x 30 and 30 x 40 matrices


respectively. What is the minimum number of multiplications required to multiply the three
matrices?
a)18000
b)12000
c)24000
d)32000

16.Which of the following is false about a binary search tree?


a)The left child is always lesser than its parent
b)The right child is always greater than its parent
c)The left and right sub-trees should also be binary search trees
d)In order sequence gives decreasing order of elements

17.In Huffman coding, data in a tree is always occur at,


a)roots
b)leaves
c)left sub trees
d)right sub trees

18.Huffman code gives,


SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing
a)an equal length code which is unique
b)a variable length code which is unique
c)an equal length code which is not unique
d)a variable length code which is not unique

19.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
Ans:c

20.Backtracking can be used to solve:


(A)Linear programming problems
(B)Problems with a single feasible solution
(C)Combinatorial optimization problems
(D)Problems with a fixed set of solutions
Answer (C)

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)

22.The data structure used for Depth First Algorithm is


a)STACK
b)QUEUE
c)BOTH STACK & QUEUE
d)NONE OF THESE

23.What is the worst case complexity of quick sort?


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

24.Graph Coloring Problem is an example of ------------------- problem


SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing
a) P
b) NP
c) NP-Complete
d) NP-Hard

25.The backtracking algorithm is implemented by constructing a tree of choices known as?


a) State-chart-tree
b) Node tree
c) Backtracking tree
d) State-space tree

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

29. he travelling salesman problem can be solved using _________


a) A spanning tree
b) A minimum spanning tree
c) Bellman – Ford algorithm
d) DFS traversal
Answer: b

30. Consider the following graph. Using Kruskal’s algorithm, which edge will be selected first?
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing

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

32. Consider the following statements.


S1. Kruskal’s algorithm might produce a non-minimal spanning tree.
S2. Kruskal’s algorithm can efficiently implemented using the disjoint-set data structure.
a) S1 is true but S2 is false
b) Both S1 and S2 are false
c) Both S1 and S2 are true
d) S2 is true but S1 is false
Answer: d

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

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing
Answer: b

34. Prim’s algorithm is a ______


a) Divide and conquer algorithm
b) Greedy algorithm
c) Dynamic Programming
d) Approximation algorithm
Answer: b

35. What is the time complexity of Dijikstra’s algorithm?


a) O(N)
b) O(N3)
c) O(N2)
d) O(logN)
Answer: c

36. Floyd Warshall’s Algorithm is used for solving ____________


a) All pair shortest path problems
b) Single Source shortest path problems
c) Network flow problems
d) Sorting problems
Answer: a

37. What is the running time of the Floyd Warshall Algorithm?


a) Big-oh(V)
b) Theta(V2)
c) Big-Oh(VE)
d) Theta(V3)
Answer: d

38. What approach is being followed in Floyd Warshall Algorithm?


a) Greedy technique
b) Dynamic Programming
c) Linear Programming
d) Backtracking
Answer: b

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

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing
Answer: b

40. What is the formula to compute the transitive closure of a graph?


a) tij(k) = tij(k-1) AND (tik(k-1) OR tkj(k-1))
b) tij(k) = tij(k-1) OR (tik(k-1) AND tkj(k-1))
c) tij(k) = tij(k-1) AND (tik(k-1) AND tkj(k-1))
d) tij(k) = tij(k-1) OR (tik(k-1) OR tkj(k-1))
Answer: b

41. What is a Rabin and Karp Algorithm?


a) String Matching Algorithm
b) Shortest Path Algorithm
c) Minimum spanning tree Algorithm
d) Approximation Algorithm
Answer: a

42. What is the pre-processing time of Rabin and Karp Algorithm?


a) Theta(m2)
b) Theta(mlogn)
c) Theta(m)
d) Big-Oh(n)
Answer: c

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

44. What is the basic principle in Rabin Karp algorithm?


a) Hashing
b) Sorting
c) Augmenting
d) Dynamic Programming
Answer: a

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

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing
Answer: b

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

47. Problems that cannot be solved by any algorithm are called?


a) tractable problems
b) intractable problems
c) undecidable problems
d) decidable problems
Answer: c

48.To which class does the Euler’s circuit problem belong?


a) P class
b) NP class
c) Partition class
d) Complete class
Answer: a

49. Which of the following problems is not NP complete?


a) Hamiltonian circuit
b) Bin packing
c) Partition problem
d) Halting problem
Answer: d

50. Hamiltonian path problem is _________


a) NP problem
b) N class problem
c) P class problem
d) NP complete problem
Answer: d

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

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing
d) assignment problem
Answer: c

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

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing
4 Mark Questions

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

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing
Character A B C D E
Count/Freq 3 5 6 4 2

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

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing
Weight 14 18 10
Capacity of Knapsack, M=20.
11. Solve and get any one feasible solution using backtracking for 4 Queens problem on a 4 by 4
chess board.
12. Given a sum and a set , find a feasible subset to get the the sum using backtracking.
S= {5,10,12,13,15,18} , Sum M=30
13. Find a Hamiltonian circuit using backtracking for given graph.

14. Find a Hamiltonian circuit using backtracking for given graph.

15. Discuss Floyd warshall algorithm for the given graph.


SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing

16. Discuss the Rabin Karp algorithm with given example.


string target = "bcac";
string source = "abcabcabcacd";
17. Discuss the vertex cover problem using approximation algorithm.
18. Discuss about different complexity classes in detail.
19. Discuss about NP complete and NP hard problems with example.

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.

3. Explain the chained matrix multiplication with suitable example


4. Discuss in detail about the class P, NP, NP-hard and NP-complete problems. Give examples
for each class
5. Describe Travelling Salesperson Problem (TSP) using Branch and Bound
6. What is state space tree? What are the different ways of searching an answer node in an state
space tree explain with example.
7. a) Write non-deterministic algorithm for knapsack problem?
b) Difference between NP-hard and NP-complete problems
8. Explain 0/1 knapsack problem dynamic programming.
9. Write a depth first search algorithm for graph traversal.
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
TIRUCHIRAPPALLI

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing
10. Define graph coloring and write an algorithm to find Hamiltonian cycles.
11. Give the solution to the 8 queen’s problems using backtracking.
12. Discuss in detail about the class P, NP, NP-hard and NP-complete problems. Give examples
for each class.
13. Find an optimal solution to the knapsack instance n=7,
14. m=15,(p1,p2,.....p7)=(10,5,15,7,6,18,3) and (w1,w2,.....w7)=(2,3,5,7,1,4,1).
15. Apply dynamic programming techniques to solves 0/1 knapsack problem for the given
scenario and analyse it’s time complexity.
P = {1,2,5,6}
W = {2,3,4,5}
M=8
N=4
16. Construct the Huffman code for the characters given below:
Character Frequency
a 5
b 9
c 12
d 13
e 16
f 45
17. Consider the given traveling salesman problem. Apply branch and bound technique for
calculating minimum cost.

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

TIRUCHIRAPPALLI FACULTY OF ENGINEERING AND TECHNOLOGY


School of Computing
20. Write a function to compute lengths of shortest paths between all pairs of nodes for the given
adjacency matrix.

21. Explain the chained matrix multiplication with suitable example


22. Discuss in detail about the class P, NP, NP-hard and NP-complete problems. Give examples
for each class
23. Describe Travelling Salesperson Problem (TSP) using Branch and Bound
24. What is state space tree? What are the different ways of searching an answer node in an state
space tree explain with example.
a) Write non-deterministic algorithm for knapsack problem?
b) Difference between NP-hard and NP-complete problems
25. Explain 0/1 knapsack problem dynamic programming.

You might also like