0% found this document useful (0 votes)
49 views

Fundamentals of Algorithms - CS502 Spring 2005 Final Term Paper

The document is the instructions for a 150 minute final exam in an algorithms course. It contains 8 multiple choice and short answer questions worth a total of 95 marks. Students are warned that cheating will result in an F grade. Some relevant formulas are provided.

Uploaded by

Muhammad Hasnain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Fundamentals of Algorithms - CS502 Spring 2005 Final Term Paper

The document is the instructions for a 150 minute final exam in an algorithms course. It contains 8 multiple choice and short answer questions worth a total of 95 marks. Students are warned that cheating will result in an F grade. Some relevant formulas are provided.

Uploaded by

Muhammad Hasnain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

WWW.VUTUBE.EDU.

PK
www.vustuff.com

CS502 Fundamentals of Algorithms


Final Term Examination – Spring 2005
Time Allowed: 150 Minutes

Please read the following instructions carefully before


attempting any of the questions:
1. The duration of this examination is 150 Mins.
2. This examination is closed book, closed notes, closed neighbors.
3. Do not ask any questions about the contents of this examination from
anyone.
a. If you think that there is something wrong with any of the
questions, attempt it to the best of your understanding.
b. If you believe that some essential piece of information is
missing, make an appropriate assumption and use it to solve
the problem.
4. Some of the examination consists of multiple-choice questions.
Choose only one choice as your answer.
a. If you believe that two (or more) of the choices are correct for a
particular question, choose the best one.
b. On the other hand, if you believe that all of the choices provided
for a particular question are wrong then select the one that
appears to you as being the least wrong.

**WARNING: Please note that Virtual University takes serious


action against unfair means. Anyone found involved in
cheating will get an `F` grade in this course.

Some results you may need:


n ( + 1)
nn n i x ( n+1) −1
∑ i=
n
2n3 + 3n2 + n x =
= 2 ∑ i =
2

6

= x −1
i 1 , i =1 , i 1
Total Marks: 95 Total Questions: 08

Question No. 1 Marks : 05

Best and worst case times of an algorithm may be same.

o True
o False
Question No. 2 Marks : 05

Can an adjacency matrix for a directed graph ever not be square in


shape?
o Yes
o No
Question No. 3 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.

Question No. 5 Marks : 25


You land at Heathrow airport for a vacation in London. Your hotel located in Essex, a
suburb of London. You will need to take the train to get to your hotel. You have a
that shows the train lines and the fares between various points in London. You would
map
to
likeminimize the fare you need to pay to travel from the airport to your hotel. To
matters complicated, the airline you traveled on gave you a discount coupon that can
make
used onone train journey. The coupon can be used only once. The coupon will get
be
50% discount youon the train fare. The coupon also lists which train lines the coupon can
used on to get the 50% discount. Solve the problem on the following sample train
be
map (node A is the airport, node B is Essex where the hotel is). The notation 40,y
lines
the fare is 40 and discount is available. If the coupon is used on this line, the fare
means
be 20. Describe the algorithm you have used to determine the train route that
would
minimizes
the total fare. [25 pts]

Question No. 6 Marks : 10

Solve the following recurrence using iteration method ( show intermediate [10 pts]
steps
T(n) =) n + 2T(n/2)
T(1) = 1

Question No. 7 Marks : 25


Recall that a dynamic programming solution to the 0-1 knapsack problem can be
from the following recurrence formula forc[i ,w], the value of the solution for items , . .
derived
. , i and maximum weightw. 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

From these inputs the followingc table is computed by the


algorithm:

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]

You might also like