CS2006-1
CS2006-1
2[b] Write an algorithm to solve the make-change problem using dynamic programming?
Suppose there are n types of coin denominations, d1, d2, …, and dn. (We may assume one of
them is penny.) There are infinite supplies of coins of each type. The problem is to make
change for an arbitrary amount j using the minimum number of coins. Comment on time
and space complexity of the algorithm
[5+5]
3[a] What is a randomized algorithm? Design a randomized algorithm rsearch(A, n, x) which will
search whether x is in the array A of n elements. If found it will terminate. Otherwise, the
algorithm is guaranteed to terminate when it finds that none of the elements in A is x.
What is the time complexity of your algorithm?
3[b] Write a divide-conquer recursive algorithm "MaxMin" to find the maximum and minimum
from a set of n elements. Modify Algorithm "MaxMin" so that it works when n is not a
power of 2. Is the number of comparisons performed by the new algorithm 3n/2-2, even
if n is not a power of 2?
[5+5]
4[a] Express, finding minimum spanning tree of an undirected connected graph as an
optimization problem. Kruskal’s algorithm for finding a minimum spanning tree employs a
minheap to store the candidate edges. If a graph has m edges, explain why the time
complexity for this algorithm must be O(m logm). In Kruskal's method for finding a
minimum spanning tree, how does the algorithm know when the addition of an edge will
generate a cycle?
Page 1 of 2
4[b] Write the control Abstraction for Divide-and-Conquer paradigm? Write the recurrence
relation to compute the time taken by a Divide and Conquer algorithm, to solve defective
chessboard problem with size [2K 2k, with k 0]? Solve the recurrence relation using
telescopic sum method.
[5+5]
5[a] Define the principal of optimality? Explain the basic 4-step process to solve optimization
problem under dynamic programming paradigm? Use LCS problem to explain this 4-step
process with appropriate algorithm?
5[b] Formulate the container loading as an optimization problem. Suggest a greedy algorithm to
find solution to the container loading. Suppose you have 6 containers whose weights are
45, 10, 30, 20, 55, and 5 and a ship whose capacity is 100. Use the algorithm to find a
greedy solution to this instance of the container loading problem.
[5+5]
6[a] What are the main steps of a backtracking algorithm? What is a dead-end in backtracking?
State the different constraints to be satisfied while solving an optimization problem using
backtracking. Discuss how BACKTRACKING is used to solve the 4-queens problem where
solution space is organized as a tree.
6[b] Discuss the structure of the knapsack problem? Explain how this problem can be solved
using Dynamic programming. Find an optimal solution the knapsack problem with instance
n =8, m=20 with ( P1, P2, .., P7, P8 ) = (10, 5, 15, 7, 6, 18, 3,2) and (w1, w2, … , w7, w8) = (2, 3,
5, 7, 1, 4, 2,1).
[5+5]
7[a] Show that average time complexity of "QuickSort" is (n log n)? Show that work space
needed by Algorithm "QuickSort" varies between (log n) and (n)? What is its average
space complexity?
7[b] Suppose that we want to multiply four matrices, A, B, C, D, of dimensions 5020, 201, 1
10, and 10 100, respectively. Multiplying an mn matrix by an np matrix takes mnp
multiplications. Determine the optimal order, if we want to compute ABCD using
dynamic programming paradigm. Create two tabular representation to find out minimum
multiplication required and parenthesizations of the matrix chain.
[5+5]
8[a] Define and differentiate between deterministic and non-deterministic algorithm? Suggest a
non-deterministic primality testing algorithm? What is the time complexity of the proposed
algorithm?
8[b] Explain the generic method for branch and bound algorithms. How does branch and bound
method solve the 0/1 Knapsack problem? Use the following instance n = 5, (p1, p2, p3, p4,
p5) = (10,15, 6, 8, 4), (w1, w2, w3, w4, w5) = (4, 6, 3, 4, 2), and m = 12 to explain branch and
bound algorithm. Will the branch and bound algorithm perform better that the dynamic
programming solution? Justify.
[5+5]
Page 2 of 2