Fundamentals of Algorithms - CS502 Spring 2005 Final Term Paper
Fundamentals of Algorithms - CS502 Spring 2005 Final Term Paper
PK
www.vustuff.com
6
∑
= x −1
i 1 , i =1 , i 1
Total Marks: 95 Total Questions: 08
o True
o False
Question No. 2 Marks : 05
2
If an algorithm has a complexity of 2n + 4n + 3 for some model of computation
set of assumptions) and some complexity measures
(some (such as number of
operations) we could say that it has
comparison
complexity
o (a) O(log2
2 n)
o (b) O(n )
o (c) O(2 + 4 + 3)
o (d) all of the above
o (e) none of the above
Question No. 4 Marks : 05
You are given the task of laying down new railway lines which will connect alln cities.
Thus for any pair of cities, you will end up with track connecting them. Note that
routes may share the same track; track laid between Lahore and Islamabad can be used
two
travel in both directions. your goal is to use the minimum amount of track. How
to
you achieve the goal now? (Note : consider the scenario carefully and name only the
would
best
suited algorithm)
o 1 Dijkstra's algorithm
o 2 Prims algorithm
o 3 Floyd Warshall algorithm
o 4 Bellman Ford algorithm.
Solve the following recurrence using iteration method ( show intermediate [10 pts]
steps
T(n) =) n + 2T(n/2)
T(1) = 1
>:
The algorithm based on this recurrence takes as inputs the maximum W, the
number of itemsn, and the two
weight v = hv1,v2, . . . ,vni and w = hw1,w2, . . . ,wni.
It stores the c[i , j ] sequences
values in a table c[0..n,0..W]. At the end of the computation,c[n,W]
contains the maximum value the thief can
In the following example the inputs n = 6,W = 8, with values vi and weightswi :
take.
are
The last part of the algorithm uses this table to determine which items the thief
should
take to achieve the maximum value, 22.
(a) Describe this last part of the algorithm: how, in general, it determines the items to
be
taken.(Note : in maximum three lines.)
(b) For the above example, list the items to take (i.e., list their indices).
[25 pts]
Question No. 8 Marks : 15
Run DFS sweep and topological sort on the directed graph defined by the
following
adjacency matrix.
[15 pts]