Design and Analysis of Algorithm - QB
Design and Analysis of Algorithm - QB
1) Define algorithm.
2) Write Characteristics of algorithm.
3) Define Space Complexity.
4) Define Time Complexity.
5) Define O notation.
6) Define θ notation.
7) Define Ω notation.
8) Define little oh notation
9) Define little omega notation.
10) List asymptotic notations
11) Define Recursive Algorithm. Give example.
12) Define Non-recursive Algorithm. Give example.
13) Give non-recursive algorithm for binary search.
14) Give recursive algorithm for binary Search.
15) Write algorithm for linear search.
16) Justify true or false 𝑛 𝑥 = 𝑂(2𝑥 )
17) Define Big-Oh notation. Is 2n+1 = O (2n)?
18) Justify true or false nn = O(2n)
19) Define Big-Oh notation. Is 2n+1 = O(2n)?
20) Write asymptotic relationship (O or Ω or 𝜃) for f and g where
f(x)=x2+1, g(x)=3x-2.
21) Write asymptotic relationship (O or Ω or 𝜃) for f and g where
f(x)=x2+5, g(x)=3x2+4x.
22) Write asymptotic relationship (O or Ω or 𝜃) for f and g where
f(x)=2x+3x, g(x)=3x+2x+1.
23) Write asymptotic relationship (O or Ω or 𝜃) for f and g where
f(x)=2x+1, g(x)=3xlog2x+2.
24) Write asymptotic relationship (O or Ω or 𝜃) for f and g where
f(x)=2log2x, g(x)=log3(2x).
25) What is stable sorting algorithm? List any two sorting algorithms that
are stable.
26) What operations do heap data structure support and what is the growth
rate of these operations?
8) Find the minimum spanning tree for the following graph using kruskal’s
algorithm
9) Raksha Bandhan was on 7th August. Ram has 4 sisters living in the
same city named Sheena, Reena, Teena, Meena. Ram required Rs. 30
autofare to goto Reena’s home and from there to Sheena’s home Rs. 27.
He can directly goto Sheena’s home with Rs. 45/-. He need Rs 20 from
Reena’s home to Meena’s home and Rs. 17 from Sheena’s home to
Meena’s home. Meena’s home to Teena’s home Rs. 25 . Ram required
Rs 33 to reach to Teena’s home from his place. Ram wants to reduce his
cost of autofare.
10) Find an optimal binary merge pattern for 10 files whose lengths are
15, 2, 12, 35, 28, 11, 23, 5, 20, 3
11) Obtain a set of optimal Huffman codes for the messages m1 to m7 with
relative frequencies
(f1, f2, f3, f4, f5, f6, f7) = (1, 1, 2, 3, 5, 8, 13)
Draw the decode tree for this set of codes.
12) Construct Huffman code for the following character set.
13)Find the length of shortest path from the source vertex A using Bellman
ford algorithm
14)Find the length of shortest path from the source vertex A using Bellman
ford algorithm
15)Find the length of shortest path from the source vertex A using Bellman
ford algorithm
16)Find the length of shortest path from the source vertex A using Bellman
ford algorithm
17)Find all pair shortest pathusing Floyd Warshall algorithm for the
following graph.
20)Find all pair shortest path using Floyd Warshall algorithm for the
following graph.
21) Find Longest Common Subsequence for the following sequences using
dynamic programming method.
Where X = ABCBDAB
Y = BDCABA
22) Find LCS of the sequences X and Y where
X = (B, D, C, A, B, A)
Y = (A, B, C, B, D, A, B)
23)Give the recurrence relation for the optimal length of LCS. Find LCS of
the sequences
X=<1, 0, 0, 1, 0, 1, 0, 1>
Y=<0, 1, 1, 0, 1, 1, 0>
24) Give the recurrence relation for the optimal length of LCS. Find LCS of
the sequences
X=<b,b,a,b,a,b,b>
Y=<b,a,b,c,a>
25) A string X can be transformed into string Y by applying a sequence of
edit operations such as insert, delete and interchange with associated
costs of 1, 1, 2 respectively. For x = (C, C, D,C, D) AND Y = (D, C, D,
D) find cost of Transforming X to Y.
26) A string X can be transformed into string Y by applying a sequence of
edit operations such as insert, delete and interchange with associated
costs of 1, 1, 2 respectively. For x = (C, C, D,C, D) and Y = (D, C, D,
D) find cost of Transforming X to Y.
27) Given sequences X=a,a,b,a,b and Y=b,a,b,b . Find an edit sequence of
minimum cost which transforms X into Y. The cost of each insertion
and deletion is 1 and the cost of changing symbols is 2.
28) Explain string editing problem. Give the recurrence relation for the value
of the optimal solution when the problem is to be solved using dynamic
programming.
29) Given sequences X=1,1,0,1,1,0,0 and Y=0,1,0,1,1,0. Find an edit
sequence of minimum cost which transforms X into Y. The cost of each
insertion and deletion is 1 and the cost of changing symbols is 2.
30) Solve Travelling Sales Person problem (TSP) using Dynamic
programming Method for the graph G given by adjacency matrix
0 10 15 20
𝐴= [5 0 9 10]
6 13 0 12
8 8 9 0
31) Solve Travelling Sales Person problem (TSP) using Dynamic
programming Method for the graph G given by adjacency matrix
0 10 10 9
𝐴= [8 0 7 3]
8 4 0 8
10 5 5 0
32) Give recurrence relation to solve TSP using Dynamic Programming
Method. Apply the same on the following instance
0 20 10 11
𝐴 = [4 0 6 2]
3 6 0 8
7 4 16 0
Q.2) 2 marks Questions.
1) Define principle of optimality. List two problems for which principle of
optimality does not hold.
2) List four problems for which principle of optimality does not hold.
3) Define matrix Chain multiplication problem.
4) What is String editing problem?
5) What do you mean by longest common subsequence problem?
6) Define TSP problem.
7) What is negative edge?
8) Differentiate between Greedy and Divide and Conquer Method.
9) Differentiate between Greedy and Dynamic method.
10) Give recurrence relation to find minimum number of scalar
multiplications required to evaluate the multiplication of matrices.
11) Give recurrence relation to solve the 0-1 knapsack problem using
dynamic programming method.[Use functional method.]
12) What do you mean by Purging rule?
13) Define Discarding Rule used in 0-1 knapsack problem.
14) Give recurrence relation to solve single source shortest path problem
using Dynamic Programming method.
15) Give recurrence relation to solve all pair shortest path problem using
dynamic programming method.
16) Give recurrence relation to solve TSP problem using dynamic
programming method.
17) Give recurrence relation for string editing using dynamic programming
method.
18) Give recurrence relation for LCS problem using dynamic programming
method.
19) What do you mean by dominance rule?
7) Draw DFS and BFS for the following graph [start vertex is A]
8) Find the topological sort of the given directed acyclic graph? What is its
time complexity?
9) Find the topological sort of the given directed acyclic graph? What is its
time complexity?
10) Define four types of edges in terms of Depth First Spanning Tree.
Illustrate all four types of edges in the following graph. [ start vertex is S]
11) Find the strongly connected components of the following graph using the
above algorithm
12) Find the strongly connected components of the following graph.
13) Find all articulation point from the following graph [Start vertex is 3]
14) Identify all articulation points from the following graph and also Identify
Bridge edges from the following graph. [Start vertex is 1]
4) What is Hamiltonian cycle? Find out all possible Hamiltonian cycle for
the following graph
5) What is Hamiltonian cycle? Find out all possible Hamiltonian cycle for
the following graph [start vertex is 2]
6) Explain sum of subset problem. Find the solution for fixed tuple size state
space n = 5, m = 30, w = {5, 7, 10, 13, 15}
7) Find the solution for variable tuple size state space n = 6, m = 22, w = {5,
7, 10, 12, 15, 17}
Q.2) 2 Marks Questions
1) What is brute force Approach?
2) Define a) Implicit Constraint b) Explicit Constraint
3) Distinguish between fixed tuple and variable tuple formulation
4) Backtracking is Breadth First search(BFS) for solution. Justify.
5) Define (Ask any two in exam)
a) State Space tree
b) Solution space of a problem
c) Problem state
d) Solution state
e) Answer state
f) Live node
g) Dead node
h) E-node
i) Killed node
6) Define n queen’s problem. Give explicit and implicit constraints for
the same.
7) Define 4 queen’s problem. Give explicit and implicit constraints for
the same.
8) Define 8 queen’s problem. Give explicit and implicit constraints for
the same.
9) Show that there is no solution for 2 queens problem
10) Show that there is no solution for 3 queens problem
11) How many solutions are there in the 8-queen problem and give
implicit constraints.
12) Define 4 queen’s problem. How many solutions are there in the 4-
queen’s problem.
13) Define Graph colouring problem. Give explicit and Implicit
constraints for the same.
14) Define m-colourability problem.
15) Define sum of subset problem.
16) Give Bounding function for sum of subsets problem using
backtracking.
17) What is Hamiltonian Cycle?
1) Define the terms (ask any six or any three with one example)
a) Deterministic Algorithm
b) Non-deterministic algorithm
c) Decision problem
d) Optimization problem
e) Knapsack decision problem
f) Knapsack Optimization problem
g) P class
h) NP class
i) NP Hard
j) NP-complete
2) Differentiate between deterministic and Non-deterministic problem.
3) State cook’s theorem. Give its Significance.
4) Write non-deterministic algorithm to sort n elements of an array. State its
time complexity.
5) Write non-deterministic algorithm to knapsack problem. State its time
complexity.
6) What is Satisfiability problem? Check whether following formula is
satisfiable or not.
X = (p q) (~p r) (~p q)
7) What is Satisfiability problem? Give non-deterministic algorithm for the
same. And check whether following formula is satisfiable or not?
X = (~p) (p q) (~q)