You are on page 1of 14

Question Bank

Subject: CSUT-112: Design and Analysis of Algorithms


CHAPTER -1 BASICS OF ALGORITHMS
Q.1) Five or Six Marks Questions:
1) Write algorithm for insertion sort and obtain its best and worst case
running time.
2) Write an algorithm to sort n integers using bubble sorting method.
Derive its time complexity.
3) Write algorithm for bubble sort and obtain its best and worst case
running time.
4) Write algorithm for counting sort and obtain its best and worst case
running time.
5) What is non-comparison sort? Explain radix sort with suitable example.
6) Sort following number with counting sort algorithm
5, 3, 1, 2, 1, 4, 1, 3, 2, 5
7) Sort following numbers with bucket sort
0.72, 0.45, 0.41, 0.56, 0.71, 0.77, 0.11
8) Explain different asymptotic notations.
8) Order the following function in ascending order of the growth rate
log2n, n, nlog2n, n2, n3, n!,2n
9) Order the following function in ascending order of the graph rate 4n, en,
nn, loge (nn) , n2, n!, loge(logen)
10) Order the following function in ascending order of the graph rate
n!, en, nn, , n2 , loge (nn)
11) Write an algorithm to check whether given number is prime or not also
find step count.
12) Write an algorithm to find minimum and maximum element from given
list. Also calculate step count and complexity.
13) Define asymptotic notation and define space complexity?
14) What is heap sort algorithm? Solve following problem using min
heapify function
100, 12, 65, 45, 1, 66, 23, 79

Q.2) Two Marks questions:

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?

CHAPTER -2 DIVIDE AND CONQUER STRATEGY


Q.1) Five or Six Marks Questions:

1) Devise a divide and conquer strategy to determine the total number of


positive numbers in an array of n numbers.
2) Write an algorithm to find sum of all elements of an array using divide
and conquer method.
3) Let A[1..n] be an array of integers. Write an efficient algorithm to find
maximum from the array using divide and conquer method.
4) Devise a divide and conquer strategy to determine occurrence of a
specific element in an array of n integers. What is its time complexity.
5) Given a sorted array of n numbers containing all but one of integers in
the range 1 through n + 1 .devise a divide and conquer based algorithm
that determines the missing number. Derive the time complexity
required for this algorithm.
6) Use strassen’s algorithm to compute the matrix product of following
matrices giving each computation step
4 3 3 −2
A=[ ] 𝐵=[ ]
5 6 −4 2
7) Show that the time complexity of Strassen’s algorithm is O(n2.81)
8) Sort the following numbers using Quick Sort 5, 5, 8, 3, 4, 3, 2. Check if
it is stable sort of not.
9) Sort the following array elements by merge sort 19, 7, 14, 10, 8, 7, 9,
16, 15.
10) Explain binary search algorithm in context of divide and conquer
method with suitable example.
11) Explain Strassen’s matrix multiplication. Derive the time complexity
required by Strassen’s matrix multiplication.
12) Solve the following recurrence relation
T(n) = a n small if n <=1
3T(n/3) + cn otherwise

Q.2) 2 Marks Questions.

1) What is Divide and Conquer Strategy?


2) Merge sort is in-place algorithm. Justify
3) What do you mean by in-place algorithm? Give example of in-place
algorithm.
4) Why quick sort is called partition and exchange sort?
5) What are limitations of Merge-Sort?
6) What is in place sorting? Give example of in place sorting.
7) Distinguish between traditional matrix multiplication and Strassen’s
matrix multiplication.
8) Write control abstraction for divide and conquer.
9) List any four algorithms that use divide and conquer strategy.
10) Give the recurrence relation of Strassen’s matrix multiplication and its
time complexity.
11) Write applications of Divide and Conquer Strategy.
12) List any two stable sorting algorithms.

CHAPTER 3 - GREEDY METHOD

Q.1) Five or Six Marks Questions:


1) Find an optimal solution to the knapsack problem instance n=7, m=15 ,
p = (10, 5, 15, 7, 6, 18, 3) , w = (2, 3, 5, 7, 1, 4, 1) using greedy strategy.
2) Find an optimal solution to the knapsack problem instance n=7, m=25 ,
p = (16, 17, 8, 3, 3, 9, 8) , w = (16, 4, 4, 5, 8, 3, 3) using greedy strategy.
3) Kartik is seventh standard student. Teacher gave assignment, project ,
music test, sports activity to the class.
ASSIGNMENTS MUSIC PROJECT SPORTS
TEST ACTIVITY
BURDEN 8 5 10 5
MARKS 10 7 20 8
Maximum burden he can take is 23 units. Help kartik to get maximum
marks with the burden he can sustain .
4) Consider the following instance for the Job sequencing with deadline
problem.
n=7, (p1, p2,….., p7) = (15, 10, 7, 8, 18, 5, 3, 25)
(d1, d2, …..,d7) = (1, 2, 2, 4, 3, 1, 7)
5) Using Job sequencing find profit for given data
N=5, P = (20, 15, 10, 5, 1) W =(2, 2, 1, 3, 3)
6) MSc Computer Science 1 students have to submit their assignments.
There are students in Kaveri Hostel. According to the rules of hostel a
student can switch on the light in night only for an hour per subject.
Tapsya wants to submit her AN assignment of 10 marks at 3pm or
before, she has to submit her NP assignment of 20 marks at 1pm or
before, DAA assignment of 15 marks at 2pm or before, DDBC
assignment of 15 marks at2pm or before and PPL assignment of 5
marks at 2pm or before. Help Tapasya to get maximum marks.
7) Using Prim’s algorithm find the minimum spanning tree of following
Graph G

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) Apply Dijkstra’s algorithm on the following graph

Q.2) 2 Marks Questions.


1) What do you mean by Greedy method?
2) Give control abstraction for Greedy method.
3) Define knapsack problem.
4) Define job sequencing with deadlines.
5) Define optimal storage on tapes.
6) Define optimal merge pattern.
7) Define optimal binary merge pattern.
8) Define Huffman code.
9) Define decode tree.
10) Define Minimum Spanning tree.
11) Give difference between Prim’s and Kruskal’s algorithm.
12) Differentiate between divide and conquer method and Greedy method.
13) Huffman code is fixed length code. Justify.
14) Greedy strategy may not always yield optimal solution. Justify.
15) With respect to greedy method, define optimal solution.
16) Partial solution obtained during the Kruskal’s algorithm is also trees.
Justify.
17) What is shortest path?
18) Find optimal MRT for storing 4 program on a tape with lengths as 12,
18, 8, 10 respectively.
19)
CHAPTER -4 DYNAMIC PROGRAMMING
Q.1) Five or Six Marks Questions.
1)What is the best way to multiply a chain of matrices with dimensions that
are 10X20, 20X30, 30X2, 2X50 using Dynamic programming method.
2)What is the best way to multiply a chain of matrices with dimensions that
are 20X5, 5X10, 10X3 and 3X7 using Dynamic programming method.
3)What is the best way to multiply a chain of matrices with dimensions that
are 15 X 3, 3X10, 10X2 and 2X30 using Dynamic programming method.
4)Give recurrence relation to find minimum number of multiplications
required to evaluate product of chain of matrices. And find best way to
multiply a chain of matrices with dimensions 5 X 4, 4X6, 6X2, 2X7.
5)What is the best way to multiply a chain of matrices with dimensions that
are 5𝑋10, 10𝑋3, 3𝑋12, 12𝑋5, 5𝑋50 using dynamic programming
method.
6)Find the minimum cost of computing product of chain of matrices having
dimension 20X5, 5X10, 10X10, 10X 5, 5X10 using dynamic
programming method.
7)Solve 0/1 knapsack problem with n=4, m=14, P=(10,15,,6,9) and
W=(2,5,8,1) (Use Function Method).
8)Solve 0/1 knapsack problem with n=4, m=12, P=(20,15,10,8) and
W=(4,5,2,3) (Use Merge and Purge Method).
9)Solve 0/1 knapsack problem with n=4, m=7, P=(5,5,6,8) and W=(1,2,3,4)
(Use Function Method).
10)Solve 0/1 knapsack problem with n=4, m=15, P=(10,10,12,18) and
W=(2,4,6,9) (Use Merge and Purge Method).
11)What is principle of optimality ? solve 0/1 knapsack problem with n=4, m
= 34, p =(2, 5, 8, 1) , w = (10, 15, 6, 9) using dynamic programming
[use function method]
12)Find the length of shortest path using Bellman ford algorithm
0 6 ∞ ∞ 7
∞ 0 5 −4 8
∞ −2 0 ∞ ∞
2 ∞ 7 0 ∞
[∞ ∞ −3 9 0 ]

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.

18)Apply Floyd Warshall algorithm to find lengths of shortest paths from


vertex u to vertex v u,v ϵ V(G), where adjacency matrix of G is
0 4 11
𝑊 = [6 0 2 ]
3 ∞ 0
19)Find all pair shortest path using 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?

CHAPTER -5 DECREASE AND CONQUER


Q.1) Five or Six Marks Questions.
1) Explain the algorithm for Breadth First Search for finding strongly
connected component. Give its Time complexity.
2) Explain the algorithm for Depth First Search for finding strongly
connected component. Give its Time complexity.
3) Show that BFT can be used to obtain the reflexive transitive closure
matrix of an undirected graph.
4) What are strongly connected components? Give the algorithm to compute
strongly connected components using DFS.
5) Draw the DFS and BFS spanning tree for the following graph
6) Give DFS and BFS for the following graph [start vertex is A]

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]

Q.2) 2 Marks Questions.


1) What are applications of Breadth First Tree.
2) What are applications of Depth First Tree.
3) Define (any two terms will be given in exam)
a) Tree edge
b) Non tree edge
c) Back edge
d) Forward edge
e) Cross edge
f) Connected Component
g) Strongly Connected Component
h) Bi-connected Component
i) Articulation Point
j) Bridge Edge
4) What is difference between tree edge and forward edge?
5) What is difference between back edge and forward edge?
6) Define the four types of edges in terms of Depth First Spanning Tree.
7) Define DAG. How to test whether given graph is DAG or not?
8) Write Euclid’s Algorithm.
9) What is topological sorting?
10) Write data structures used in DFS and BFS.
CHAPTER -6 BACKTRACKING
Q.1) Five or Six Marks Questions:
1) Define 4 queen’s problem. Draw state space tree to find solution for 4
queen’s problem using backtracking.
2) Find out all possible solutions for the following graph coloring problem
with m=3. Also show that only 12 solutions exist with exactly 3 colors

3) What is m-colourability problem? Find out all possible solution with 3


colour for the following graph.

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?

CHAPTER -7 BRANCH AND BOUND


Q.1) Five or Six Marks question.
1) Obtain reduced cost matrix for the TSP instance given by the following
matrix
∞ 10 12 9
[7 ∞ 6 4]
9 4 ∞ 4
11 10 5 ∞
Which node will be selected next in the LCBB formulation of the
problem?
2) Solve the given instance of TSP by using reduced cost matrix method
∞ 20 30 10
[15 ∞ 16 4 ]
3 5 ∞ 2
19 6 18 ∞
3) Draw the portion of the state space tree generated by LCBB for 0/1
knapsack problem instance given by n = 3, m = 10, p = (8, 5, 5) , w = (6,
5, 5)
4) Draw the portion of the state space tree generated by LCBB for 0/1
knapsack problem instance given by
n = 4, m = 15, p = (10, 10, 12, 18), w = (2, 4, 6, 9)

Q.2) 2 marks Questions


1) Why Least Cost search method is preferred over LIFO and FIFO Branch
Bound method
2) Write condition for kill a node, update the u in LCBB and what is the
initial value of u.
3) What is bounding function?
4) Why bounding function are useful in the context of branch and bound.
5) Define FIFOBB and LIFOBB.
6) Differentiate between FIFOBB and LIFOBB.
7) LIFOBB and FIFOBB methods are rigid. Justify.
8) What do you mean by branch and bound? Give an example of an
application where this technique might be useful.
9) Give the bounding function for 0-1 knapsack problem using branch and
bound method.
10) Write two bouncing functions associated with every node in LCBB.
CHAPTER -8 PROBLEM CLASSIFICATION
Q.1) Five or Six marks questions:

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)

You might also like