You are on page 1of 4

425

APRIL-MAY 2017 EXAMINATION


IV B.E. (4YDC) EXAM
CO3463: DESIGN AND ANALYSIS OF ALGORITHMS
Time: 3 Hrs.] [Max. Marks: 70
[Min. Marks: 22
Note: Attempt all the questions. Each question have four sub-parts a, b, c and d. Attempt any one
part out of (a) and (b), and similarly any one part out of (c) and (d). Attempt all sub-parts of a question
at one place.
Q 1. (a) Solve the following recurrence relations: [08]
(i) T(n)= 3T(n/4)+ n1/4 log n if n >4 otherwise T(n)=1
(ii) T(n) = 2T(n-1)+Θ(1) if n >1 otherwise T(n)=1
OR
(b) (i) Suppose you are choosing between the following three algorithms: [08]
1. Algorithm A solves problems by dividing them into five subproblems of half
the size, recursively solving each subproblem, and then combining the
solutions in linear time.
2. Algorithm B solves problems of size n by recursively solving two subproblems
of size n – 1 and then combining the solutions in constant time.
3. Algorithm C solves problems of size n by dividing them into nine subproblems
of size n/3, recursively solving each subproblem, and then combining the
solutions in O(n2) time.

What are the running times of each of these algorithms (in big-O notation), and
which would you choose?
(ii) How many times F(i) (where 1<i<n) is calculated in Fibonacci series? if Fibonacci
number is calculated by following recursive function;
F(n)=F(n-1)+F(n-2) n>1 otherwise F(n)=1

(c) Consider the following algorithm: [06]

Element fun( Set S, Integer k)


Choose an element p of S;
S1 = ∅; S2 = ∅;
for ( each element x of S–{p} )
if ( x < p )
S1 = S1 ∪ {x};
else if ( x > p )
S2 = S2 ∪ {x};
if ( k ≤ |S1| )
return fun( S1, k);
else if ( k ≥ |S1|+2 )
return fun( S2, k–1–|S1|);
else
return p;

(i) What is the output of the above algorithm?


(ii) What is the recurrence relation and time complexity of the above algorithm?
OR

1 Of 4
(d) What is code tuning techniques (CTT)? Improve the following code using the CTT: [06]

(i) if ((a && !c) || (a && b && c)) {


val = 1;
} else if ((b && !a) || (a && c && !b)) {
val = 2;
} else if (c && !a && !b) {
val = 3;
} else {
val = 0;
}

(ii) for (i=0; i<n; i++)


a[i] = i*conversion;

Q 2. (a) You are given two sorted lists of size m and n. Design an O(log m + log n) time [07]
algorithm for computing the kth smallest element in the union of the two lists.
OR
(b) You are given an infinite array A[] in which the first n cells contain positive integers [07]
in sorted order and the rest of the cells are filled with 0. You are not given the value
of n. Describe an algorithm that takes an integer x as input and finds a position in
the array containing x, if such a position exists, in O(log n) time. (If you are disturbed
by the fact that the array A has infinite length, assume instead that it is of length n,
but that you don't know this length, and that the implementation of the array data
type in your programming language returns the error message ∞ whenever
elements A[i] with i > n are accessed.)
(c) Consider the following problem. The input consists of n positive integers V = {v 1,…, [07]
vn}. Let L = ∑ v . The problem is to determine if there are three disjoint subsets S,
P and T of V such that:
Vi = Vi = V

That is, no element of V can be in more than one of S, P and T. You want the sum
of the numbers in S to be equal to the product of the numbers in P, and equal to the
sum of the cubes of the numbers in T. It is okay for a number to be in none of S, P
or T. Give an algorithm for this problem whose running time is polynomial in n and
L.
OR
(d) Write an algorithm to find the longest fully dividing subsequence of a given sequence [07]
a1,a2,…,aN where ai divides aj whenever i < j. For example, 2,8,320 is a longest fully
dividing subsequence of the sequence 2,3,7,8,14,39,145,76,320.

Q 3. (a) The setting for this problem is storage system with a fast memory consisting of k [07]
pages and a slow memory consisting of n pages. At any time, the fast memory can
hold copies of up to k of the pages in slow memory. The input consists of a sequence
of pages from slow memory, think of these as being accesses to memory. If an
accessed page is not in fast memory, then it must be swapped into fast memory,
and if the fast memory was full, some page must selected to be evicted from fast
memory. The goal is to determine the pages to evict so as to minimize the total
number of evictions. Consider for example that k = 2, n = 4 pages are named A, B,
C and D, and the access sequence is A B C A. Then after the first two pages, the

2 Of 4
fast memory contains A and B. When C is accessed then either A or B must be
evicted. If B is evicted then no further evictions are necessary, and the total number
of evictions is 1. If A was evicted, then either B or C must be evicted when A is
accessed again, and the total number of evictions would be 2. Design a greedy
algorithm for this problem and prove that it is correct using an exchange argument.
OR
(b) Consider the following problem. The input consists of n skiers with heights p 1,.., pn, [07]
and n skies with heights s1, . . . , sn. The problem is to assign each skier a ski to
minimize the average difference between the height of a skier and his/her assigned
ski. That is, if the ith skier is given the α(i)th ski, then you want to minimize:

1/n |pi − sα(i)|

So for example, if p1 = 10, p2 = 20, p3 = 30, s1 = 100, s2 = 200, and s3 = 300. Then
the matching α(1) = 3, α(2) = 2, and α(3) = 1, which matches the first person to the
third ski, the second person to the second ski, and the third person to the first ski,
would have average difference
(|10 − 300| + |20 − 200| + |30 − 100|)/3 = 180

(i) Consider the following greedy algorithm. Find the skier and ski whose height
difference is minimized. Assign this skier this ski. Repeat the process until every
skier has a ski. Prove or disprove that this algorithm is correct.
(ii) Consider the following greedy algorithm. Give the shortest skier the shortest ski,
give the second shortest skier the second shortest ski, give the third shortest
skier the third shortest ski, etc. Prove or disprove that this algorithm is correct.
(c) In a directed graph, given a start node and an end node, design an algorithm to find [07]
the minimum number of vertices that need to be removed so that the start node and
end node are disconnected.
OR
(d) Given a string s, Design an algorithm to partition s such that every string of the [07]
partition is a palindrome. Return all possible palindrome partitioning of s using
backtracking?

Q 4. (a) Suppose we wish to multiply five matrices of real numbers M1 x M2 x M3 x M4 x M5 [06]


where,
M1 is 10 by 1, M2 is 1 by 50, M3 is 50 by 5, M4 is 5 by 10; and
M5 is 10 by 50.
Find the optimal order in which to multiply the matrices so as to minimize the total
number of scalar operations.
OR
(b) Write an algorithm for longest common sub-sequence (LCS). Also determine the [06]
LCS of <A,C,A,A,B,C,D,A,B,A> and <C,A,C,C,A,B,B,C,B,A>.
(c) We consider the problem of computing the longest increasing subsequence of a [08]
sequence x1, . . . , xn of integers.
(i) Give a dynamic programming algorithm to compute the length of the longest
increasing subsequence in time O(n2). Make sure to explain where to look in the
table for the answer after the table is constructed. Read the next two parts of the
question before answering this question.
(ii) Show the table/array that your algorithm constructs on the input
12,18,24,1,15,2,3

3 Of 4
(iii) Explain how to reconstruct the actual shortest increasing subsequence from the
filled in table in time O(n).
OR
(d) Consider a state consisting of n counties C1, …, Cn, with populations P1,…, Pn. You [08]
have to partition the counties in k districts. But to avoid charges of gerrymandering,
each district has to contain consecutive counties. So if a district contains county C i
and county Cj then it must contain each county Ck where i<k<j. The objective is to
minimum the difference between the county with the most aggregate people and
the county with the least aggregate people.
For example, if n = 7, k = 3 and P1 = 5, P2 = 6, P3 = 1, P4 = 7, P5 = 5, P6 = 12, and
P7 = 20. One feasible partition into districts is {C1,C2,C3}, {C4,C5,C6}, and {C7}. The
aggregate sizes of the districts would then be 12, 24 and 20. And the objective value
would be 24 - 12 = 12. This is clearly not an optimal solution.
Give a dynamic programming algorithm to find the optimal objective value. Your
algorithm need not compute the actual partition of the county into districts. The
running time of your algorithm must be bounded by a polynomial in n. The running
time should not depend on the size of the populations.

Q 5. (a) Show that if one of the following three problems has a polynomial time algorithm [08]
then they all do.
(i) The Independent Set Problem: The input is a graph G and an integer k. The
problem is to determine if G contains an independent set of size k. An
independent set is a collection of mutually nonadjacent vertices.
(ii) The Clique Problem: The input is a graph G and an integer k. The problem is to
determine if G contains a clique of size k. A clique is a collection of mutually
adjacent vertices.
(iii) The Vertex Cover Problem: The input is a graph G and an integer k. The problem
is to determine if G contains a vertex cover of size k. A vertex cover is a collection
S of vertices with the property that every edge is incident on at least one vertex
in S.
OR
(b) Boolean Satisfiability Problem: Whether the variables of a given Boolean formula [08]
can be consistently replaced by the values TRUE or FALSE in such a way that the
formula evaluates to TRUE. If this is the case, the formula is called satisfiable. On
the other hand, if no such assignment exists, the function expressed by the formula
is FALSE for all possible variable assignments and the formula is un-satisfiable.
Prove Boolean Satisfiability Problem is a NP problem.
(c) What are approximation algorithms? Solve the sum-of-subset using approximation [06]
approach if list is {1,3,5,7,11,13,17,19} and M=30.
OR
(d) Differentiate between the Data stream and Parallel algorithm by some suitable [06]
example.
********

4 Of 4

You might also like