You are on page 1of 3

418

APRIL 2018 EXAMINATION


III B.E. (4YDC) EXAM
CO34563 & CO3463: Design and Analysis of Algorithms
Time: 3 Hrs.] [Max. Marks: 70
[Min. Pass. Marks: 22
TOTAL NO. OF QUESTIONS IN THIS PAPER : 5
Note: Attempt all the questions. All parts of Question 1 are compulsory. Questions 2, 3, 4 and 5, have four parts (a),
(b), (c) and (d), attempt any one part from (a) and (b), and any one part from (c) and (d). Attempt all parts of a
question at one place.
Q1 a Solve the following recursive relations: [04]
i) T(n) = 3T(n/2) + nloglog(n), if n>1, 1 otherwise
ii) T(n) = 2T(n-1) + n, if n>1, 1 otherwise

b Arrange following functions in ascending order of their time complexity: [02]

c Consider following code: [04]


f(m, n) {
if (m == 0) return n;
else {
q = m div 10;
r = m mod 10;
return f(q, 10*n + r);
}
}
g(m, n) {
if (n == 0) return m;
else {
q = m div 10;
r = m mod 10;

return g(f(f(q, 0), r), n-1);


}
}

What do above functions do? Analyse above code to find running time complexity of f(m,n) and g(m,n).

d i) Why code tuning techniques (CTT) are required? Can CTT be used to improve time complexity of [02]
an algorithm? Justify your answer.
ii) Optimize following C code snippet, as much as possible: [02]
for (i=0;i<n;i++)
for (j=0;j<n;j++)
if(i%2)
{
x[i]+= 4*j + 5*i;
y[i]+= 7 + 4*j;
}

Q2 a The frequency of a number in an array is the number of times it appears in the array. Describe an [07]
algorithm that finds the most frequent number in an array of n numbers. If there are multiple numbers
with highest frequency then list them all. Analyze the complexity of your algorithm.

Page 1 of 3
OR

b An array contains n elements, out of which only log(n) are unique. Design an algorithm and suitable [07]
data structure to sort the array in O(nloglog(n)) time complexity and O(logn) space complexity.
c Two sorted arrays A and B have n elements each. Design an efficient algorithm to find out median, if [07]
elements of A and B are taken together.
OR
d For each of the following sorting algorithms, write their best and worst case scenarios: [07]
i) Quick sort
ii) Merge sort
iii) Insertion sort
iv) Bubble sort
v) Selection sort
vi) Heap sort
vii) Counting sort

Q3 a Suppose we wish to multiply 5 matrices A, B, C, D and E, to compute AxBxCxDxE. Following are the [07]
dimensions of the matrices:
A : 30 x 35
B : 35 x 15
C : 15 x 5
D : 5 x 20
E : 20 x 25

Write optimal substructure for matrix chain multiplication. Also, find optimal order of multiplying these
matrices, so that minimum number of scalar operations are performed.
OR
b Write optimal substructure to find longest common subsequence (LCS). Find LCS of following two [07]
DNA sequenences: ACCGGTCGAGTGCGC and CCGTTGCTCTGTAAA
c i. The four queens problem is the problem of placing four queens on an 4×4 chessboard such that [03]
none of them attack one another (no two are in the same row, column, or diagonal). Solve this
problem step by step using backtracking.
ii. Using Dijkstra’s algorithm, find shortest path in following graph, taking v1 as source vertex.
[04]

OR
d Consider following pairs:(a,45), (b,13), (c,12), (d,16), (e,9), (f,5). Each pair contains a character and [07]
corresponding frequency (in 1000’s) in a file.
i. Construct Huffman tree and find codes for these characters.

Page 2 of 3
ii. How much percentage space is saved by Huffman encoding, assuming ASCII codes were used
before compression?
iii. Encode following string using above Huffman codes: faecdb.
iv. Decode following encoded string using above Huffman codes: 10011011011100000

Q4 a Legendary Indian mathematician, Srinivasa Ramanujan worked on a problem to find number of ways a [07]
number can be written as sum of other smaller numbers, lets call it Srinivasa Ramanujan Number
(SRN).
e.g. SRN(4) = 4, as 4 can be written as sum of smaller numbers in following 4 ways:
4=1+3
=2+2
=2+1+1
=1+1+1+1

Design an efficient algorithm to compute SRN(n).


OR
b Let a0, a1, a2, ... be an integer sequence defined by: [07]
• a0 = 1;
• for n ≥ 1, an is the sum of the digits of all preceding terms.

The sequence starts with 1, 1, 2, 4, 8, 16, 23, 28, 38, 49, ...
Write an efficient algorithm to compute an where 1015 ≥ n

c Design an efficient algorithm to find sum of digits of all numbers in range 1 to n (both inclusive). Where [07]
1<=n<=10^15. For example, if n =11, then the sum is 48, as 1+2+3+4+5+6+7+8+9+(1+0)+(1+1) = 48
OR
d A graph is called Eulerian if it is possible to draw the given graph without lifting pencil from the paper [07]
and without tracing any of the edges more than once”. More formally the graph has Euler path. A Euler
path is a path that traverses all the edges in the graph, and it traverses each edge once (it can traverse a
vertex more than once). Design an algorithm that tests if a given unweighted, connected and undirected
graph is Eulerian or not.

Q5 a Write and explain Cook’s theorem. What is its significance? [07]


OR
b Describe P, NP, NP-Complete and NP-Hard classes. Explain their significance. [07]
c What are parallel algorithms? Why parallelising any algorithm has become important in recent times? [07]
Describe two examples of parallel algorithms.
OR
d What are approximate algorithms? Why do we need them? Explain with an example. [07]

Page 3 of 3

You might also like