You are on page 1of 4

WWW.VUTUBE.EDU.

PK
www.vustuff.com
CS502 Fundamentals of Algorithms
Final Term Examination - February 2005
Time Allowed: 150 Minutes

Instructions
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 note of


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

Total Marks: 80 Total


Questions: 9

Question No. 1 Marks : 10

Answer yes or no and give a brief explanation for your choice.

(a) Kruskals algorithm for minimum weight spanning trees is an example of dynamic
programming algorithm.

(b) An arbitrary graph with G (V, E), with |E| = |V|-1 edges is a tree.
(c) If problem A reduces (is polynomial-time reducible) to problem B and B is NP-
complete then A is NP-complete.

(d) Every problem in NP is NP-complete.

(e) If problem A reduces to problem B and B is in P, then A is in P.

Question No. 2 Marks : 5

If a problem is not in P, it must be NP-complete.

1 True
2 False
3 Unknown

Question No. 3 Marks : 5

Consider the following code:


for (j=1; j<n;j++)
for (k=1; k<15;k++)
for(l=5; l<n; l++)
{
Do_something_constant();
}
What order is the execution of this code?

1 O( n)
3
2 O( n )
2
3 O( n log n)
2
4 O( n )

Question No. 4 Marks : 5

Given a list of N integers, the 3-sum problem is to determine whether there exists 3 integers
in the list (not necessarily distinct) such that x + y + z = 0. Suppose that you are executing the
brute force algorithm below on a computer that executes 1 billion operations (addition,
increment, or comparison) per second.

int brute(int a[], int N)


{
int i, j, k;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
for (k = 0; k < N; k++)
if (a[i] + a[j] + a[k] == 0) return 1;
return 0; // none found
}

(a) Estimate how many seconds it will take (in the worst case) to solve a problem of size N =
1,000? Full credit if you are within 1% of the exact answer.
(b) Of size N = 10,000?

Question No. 5 Marks : 5

What is the solution to the recurrence T(n) = T(n/2)+n, T(1) = 1

1 O(logn)
2 O(n)
3 O(nlogn)
2
4 O(n )
5 O(2n)

Question No. 6 Marks : 10

Consider the following undirected graph

(0-1, 1) (0-4, 4) (0-6, 1) (0-5, 2) (1-2, 1) (1-4, 2)


(1-6, 3) (2-3, 2) (2-5, 3) (3-4, 1) (4-5, 1) (5-6, 3)

Where (i-j, w) means that the edge that connects node i to node j has weight w. give the
parent-link representation of the shortest-paths tree from node 0 that is computed by
Dijkstra's algorithm for the graph using the standard adjacency-lists representation.

Question No. 7 Marks : 5

Consider the following recurrence equation:


T(1) = 5
T(n) = 2+T(n - 1) for n ≥ 2
T(n) =

Question No. 8 Marks : 20

Consider the following undirected network with edge weights as show:


(a) List the edges in the MST in the order that Prim's algorithm chooses them. Start Prim's
algorithm from vertex 1.
(b) List the edges in the MST in the order that Kruskal's algorithm selects them.

Question No. 9 Marks : 5

Kruskals algorithm (choose best non-cycle edge) is better than Prim's (choose best tree
edge) when the graph has relatively few edges.

1 True
2 False
3 Unknown

You might also like