You are on page 1of 12

FACULTY OF ENGINEERING & TECHNOLOGY, SRM IST

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


Cycle Test – III BATCH – II ANSWER KEY
Academic Year: 2018-2019
Program offered: B.Tech (CSE) Year / Sem: II/IV
Max. Marks: 50 Duration: 100 Minutes Date of Exam: 23/04/19
Course Code and Title: 15CS204J—Algorithm Design and Analysis
PART A

Answer any FIVE questions 5*4=20 marks


Sl.No Question Course Bloom’s Marks
Outcome Taxonomy

1 What is Travelling Salesmen Problem? How dynamic programming is j Knowledge 4


useful for solving it?

Travelling Salesman Problem (TSP): Given a set of cities and


distance between every pair of cities, the problem is to find the
shortest possible route that visits every city exactly once and returns
to the starting point.

Let the given set of vertices be {1, 2, 3, 4,….n}. Let us consider 1 as


starting and ending point of output. For every other vertex i (other
than 1), we find the minimum cost path with 1 as the starting point, i
as the ending point and all vertices appearing exactly once. Let the
cost of this path be cost(i), the cost of corresponding Cycle would be
cost(i) + dist(i, 1) where dist(i, 1) is the distance from i to 1. Finally,
we return the minimum of all [cost(i) + dist(i, 1)] values. This looks
simple so far. Now the question is how to get cost(i)?
To calculate cost(i) using Dynamic Programming, we need to have
some recursive relation in terms of sub-problems. Let us define a
term C(S, i) be the cost of the minimum cost path visiting each vertex
in set S exactly once, starting at 1 and ending at i.
We start with all subsets of size 2 and calculate C(S, i) for all subsets
where S is the subset, then we calculate C(S, i) for all subsets S of
size 3 and so on. Note that 1 must be present in every subset.
If size of S is 2, then S must be {1, i},
C(S, i) = dist(1, i)
Else if size of S is greater than 2.
C(S, i) = min { C(S-{i}, j) + dis(j, i)} where j belongs to S, j != i and
j != 1.
For a set of size n, we consider n-2 subsets each of size n-1 such that
all subsets don’t have nth in them.
Using the above recurrence relation, we can write dynamic
programming based solution. There are at most O(n*2n) subproblems,
and each one takes linear time to solve. The total running time is
therefore O(n2*2n). The time complexity is much less than O(n!), but
still exponential. Space required is also exponential. So this approach
is also infeasible even for slightly higher number of vertices.
2 Construct the partial state space tree for 4-Queens problem using d Synthesis 4
backtracking.

Solutions: (2,4,1,3) and (3,1,4,2)

3 Color the following graph using graph coloring algorithm. What is the j,d Knowledge 4
minimum number of colors required?

The smallest number of colors needed to color a graph G is called its


chromatic number. The graph can be colored minimum 3 colors.

4 Generate a permutation tree for the set { 1 , 2 , 3 } a Comprehensi 4


on

5 Write the procedure to solve matrix chain multiplication problem j,d Application 4
For the chain matrix problem, like other dynamic programming
problems, involves determining the optimal structure (in this case, a
parenthesization). We would like to break the problem into
subproblems, whose solutions can be combined to obtain a solution to
the global problem.

For convenience, let us adopt the notation Ai .. j, where i ≤ j, for the


result from evaluating the product Ai Ai + 1 ... Aj. That is,

Ai .. j ≡ Ai Ai + 1 ... Aj , where i ≤ j,

It is easy to see that is a matrix Ai .. j is of dimensions pi × pi + 1.

In parenthesizing the expression, we can consider the highest level of


parenthesization. At this level we are simply multiplying two matrices
together. That is, for any k, 1 ≤ k ≤ n − 1,

A1..n = A1..k Ak+1..n .

Therefore, the problem of determining the optimal sequence of


multiplications is broken up into two questions:

Question 1: How do we decide where to split the


chain? (What is k?)

Question 2: How do we parenthesize the


subchains A1..k Ak+1..n?

The subchain problems can be solved by recursively applying the


same scheme. On the other hand, to determine the best value of k, we
will consider all possible values of k, and pick the best of them.
Notice that this problem satisfies the principle of optimality, because
once we decide to break the sequence into the product , we should
compute each subsequence optimally. That is, for the global problem
to be solved optimally, the subproblems must be solved optimally as
well.

The key observation is that the parenthesization of the "prefix"


subchain A1..k within this optimal parenthesization of A1..n. must be
an optimal parenthesization of A1..k.

The second step of the dynamic programming paradigm is to define


the value of an optimal solution recursively in terms of the optimal
solutions to subproblems. To help us keep track of solutions to
subproblems, we will use a table, and build the table in a bottomup
manner. For 1 ≤ i ≤ j ≤ n, let m[i, j] be the minimum number of scalar
multiplications needed to compute the Ai..j. The optimum cost can be
described by the following recursive formulation.
The third step of the dynamic programming paradigm is to construct
the value of an optimal solution in a bottom-up fashion.

6 Distinguish between randomized and deterministic algorithm d Analysis 4

7 What is NP-Hard problem? How to handle NP-hard problems to find b,j Knowledge 4
solution?

NP is set of decision problems that can be solved by a Non-


deterministic Turing Machine in Polynomial time. P is subset of NP
(any problem that can be solved by deterministic machine in
polynomial time can also be solved by non-deterministic machine in
polynomial time).
Informally, NP is set of decision problems which can be solved by a
polynomial time via a “Lucky Algorithm”, a magical algorithm that
always makes a right guess among the given set of choices
(Source Ref 1).
NP-complete problems are the hardest problems in NP set. A decision problem
L is NP-complete if:
1) L is in NP (Any given solution for NP-complete problems can be
verified quickly, but there is no efficient known solution).
2) Every problem in NP is reducible to L in polynomial time

A problem is NP-Hard if it follows property 2 mentioned above,


doesn’t need to follow property 1. Therefore, NP-Complete set is also
a subset of NP-Hard set.

Decision vs Optimization Problems


NP-completeness applies to the realm of decision problems. It was
set up this way because it’s easier to compare the difficulty of
decision problems than that of optimization problems. In reality,
though, being able to solve a decision problem in polynomial time
will often permit us to solve the corresponding optimization problem
in polynomial time (using a polynomial number of calls to the
decision problem).

PART B
Answer all the questions 2*15=30 marks
Sl.No Question
8 a) Discuss the algorithm for solving Sum of Subsets problem.
Let the instances be n = 6, Sum m = 30 and
w[1 : 6 ] = {5,10,12, 13, 15, 18 }. Draw the portion of state space tree generated for the above
instances.

[7 MARKS]
Three Solutions exists

A ( 1,1,0,0,1) , B (1,0,1,1) and C(0,0,1,0,0,1)


[8 MARKS]

8 b) Explain the procedure for solving 0/1 knapsack problem using the branch and bound technique.
Assume knapsack capacity W = 10:

ITEM WEIGHT PROFIT


1 7 42
2 3 12
3 4 40
4 5 25
Find the optimal solution and draw the complete state space tree.
[5 MARKS]
[5 MARKS]
[5 MARKS]

9 a) Calculate the minimum cost path from‘s’ to ‘t’ in the following multistage graph. Solve the problem
using Forward approach.
Explanation is required in steps

9 b) Solve the following Travelling Salesmen Problem using branch and bound technique:

Draw the state space tree


Reduced Cost Matrix [2 MARKS]

[10 MARKS]
State Space tree

[3 MARKS]

You might also like