DAAT2

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

K L UNIVERSITY

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


III/IV B.Tech Semester I
DESIGN AND ANALYSIS OF ALGORITHMS (13-CS-302)
2016-17
Test 2 Key
1a) Discuss optimal storage on tapes problem.
There are n programs that are to be stored on a computer tape of length L.
Associated with each program i is a length Li, 1 i n.

All programs can be stored on the tape iff the sum of the lengths of the programs is at
most L.
Assume the tape is initially positioned at the front. If the programs are stored in the order
I = i1, i2, , in, the time tj needed to retrieve program ij .
tj = lik ,1kj

If all programs are retrieved equally often, then the mean retrieval time (MRT)
=

This problem fits the ordering paradigm. Minimizing the MRT is equivalent to
minimizing
d(I) = lik,1kj,1jn

If there are m > 1 tapes, T0,T1,T2, .Tm-1 then programs are to be distributed
over these tapes.

If Ii is the storage permutation for the subset of programs on tape j, then total retrieval
time (TD) is d(Ij)
The objective is to store the programs in such away as to minimize TD.

1b) Find an optimal placement for 13 programs on three tapes T0, T1 and T2 where the

programs are of lengths 12 , 5 , 8 , 32 , 7 , 5 , 18 ,26 ,4, 3, 11, 10 and 6 and also analyze its
algorithm.
Algorithm Store(n, m)
// n is the number of programs and m the number of tapes
{
j : = 0; // next tape to store on
for i := 1 to n do
{
Write (append program, i , to permutation for tape, j);
j : = (j+1) mod m ;
}
}

2a)Explain the procedure for finding minimum cost spanning tree using kruskals method.
Kruskals Method
1) Start with a forest that has no edges.

2)Add the next minimum cost edge to the forest if it will not cause a cycle.
3)Continue this process until the tree has n - 1 edges.
2b)Construct a minimal spanning tree for the tree with the following graph using Kruskal's
algorithm

3) Show how to construct minimum spanning tree of the graph using

a) prims algorithm

b) kruskals algorithm Ref Book: R6:23.4,pp.633

a) Prims algorithm

b) Kruskals algorithm

4.Solve the following 0/1 knapsack instance using dynamic programming when n=5,
m=6,P={25,20,15,40,15} and W={3,2,1,4,5}.

5. Apply Dynamic Programming to solve all pairs shortest path problem with suitable example

and also write its algorithm.


Problem Statement

Let G=( V,E ) be a directed graph consisting of n vertices.


Weight is associated with each edge.
The problem is to find a shortest path between every pair of nodes.
Algorithm
Algorithm AllPaths( c, A, n )
// c[1:n,1:n] cost matrix
// d[i,j] is the length of a shortest path from i to j
{
for i := 1 to n do
for j := 1 to n do
A [ i, j ] := c [ i, j ] ;
// copy c into d
for k := 1 to n do
for i := 1 to n do
for j := 1 to n do
A [ i, j ] := min ( A [ i, j ] , A[ i, k ] + A [ k, j ] );
}

6. Find shortest path from node 1 to every other node of fig using Bellman and Ford algorithm..

You might also like