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

(2015) ADA-2nd internals-QN+Ans - Key

This document outlines an exam for an algorithms analysis course. It includes questions on asymptotic analysis, graph representations, the master's theorem, dynamic programming, greedy algorithms, and matrix chain multiplication.

Uploaded by

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

(2015) ADA-2nd internals-QN+Ans - Key

This document outlines an exam for an algorithms analysis course. It includes questions on asymptotic analysis, graph representations, the master's theorem, dynamic programming, greedy algorithms, and matrix chain multiplication.

Uploaded by

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

DIVISION OF COMPUTER SCIENCE AND ENGINEERING

SCHOOL OF ENGINEERING

B. TECH DEGREE II INTERNAL EXAMINATION NOVEMBER 2021

Semester VII Course Title: CS15-1703 ANALYSIS AND DESIGN OF ALGORITHMS

Faculty: Mrs Remyamol K M

Time: 2Hrs Max. Marks: 50

CO1: Analyse the worst case and average case running times of algorithms using asymptotic analysis.
CO3: Understand the dynamic programming paradigm and its algorithmic design situations
CO4: Familiarise the greedy design technique.

Part A (Answer All Questions) (5x 4 = 20)


I. a. Explain asymptotic notations. CO-1
b. State Masters theorem. CO-1
c. Explain strongly connected and biconnected components of a graph. CO-3
d. Differentiate dynamic programming and greedy method. CO-4
e Explain Warshalls algorithm for finding transitive closure of a graph. CO-3

Part B (Answer Any Three Questions) (3 x 10 = 30)


II. Explain graph reprentation and graph traversal in detail. CO-3
III. A)Solve the following equations by Masters theorem CO-1
a) T(n)=2T(n/2)+n2 by Masters theorem
b) T(n)=8T(n/2)+n3 by Masters theorem
c) T(n)=T(n/2)+1 by Masters theorem

B)Solve the following equation by using recurrence method


T(n)=T(n-1)+n

IV. Obtain optimal binary search tree for the following. CO-3
Keys 10 20 30 40
Frequency 4 2 6 3

V. The matrices have size 3 x 2, 2 x 4, 4 x 2, 2 x 5. We need to compute M [i,j], CO-3


0 ≤ i, j≤ 5 by using dynamic programming approach of Matrix chain
multiplication.

*******************************
ANSWER KEY

I a). There are mainly three asymptotic notations:


 Big-O notation (1 mark)
 Omega notation(1 mark)
 Theta notation(1 mark)
Figures(1 mark)

Asymptotic Notations:
Asymptotic Notation is a way of comparing function that ignores constant factors and small input sizes.
Three notations are used to calculate the running time complexity of an algorithm:
1. Big-oh notation: Big-oh is the formal method of expressing the upper bound of an algorithm's
running time. It is the measure of the longest amount of time. The function f (n) = O (g (n)) [read as "f
of n is big-oh of g of n"] if and only if exist positive constant c and such that
f (n) ⩽ k.g (n)f(n)⩽k.g(n) for n>n0n>n0 in all case
Hence, function g (n) is an upper bound for function f (n), as g (n) grows faster than f (n)

For Example:
1. 1. 3n+2=O(n) as 3n+2≤4n for all n≥2
2. 2. 3n+3=O(n) as 3n+3≤4n for all n≥3
Hence, the complexity of f(n) can be represented as O (g (n))
2. Omega () Notation: The function f (n) = Ω (g (n)) [read as "f of n is omega of g of n"] if and only if
there exists positive constant c and n0 such that
F (n) ≥ k* g (n) for all n, n≥ n0
For Example:
f (n) =8n2+2n-3≥8n2-3
=7n2+(n2-3)≥7n2 (g(n))
Thus, k1=7
Hence, the complexity of f (n) can be represented as Ω (g (n))
3. Theta (θ): The function f (n) = θ (g (n)) [read as "f is the theta of g of n"] if and only if there exists
positive constant k1, k2 and k0 such that
k1 * g (n) ≤ f(n)≤ k2 g(n)for all n, n≥ n0

For Example:
3n+2= θ (n) as 3n+2≥3n and 3n+2≤ 4n, for n
k1=3,k2=4, and n0=2
Hence, the complexity of f (n) can be represented as θ (g(n)).
The Theta Notation is more precise than both the big-oh and Omega notation. The function f (n) = θ
(g (n)) if g(n) is both an upper and lower bound.

b) Master’s method ->1 Mark for each cases+explanation(1)


T(n) = aT(n/b) + f(n)
where, T(n) has the following asymptotic bounds:
1. If f(n) = O(nlogb a-ϵ), then T(n) = Θ(nlogb a).
2. If f(n) = Θ(nlogb a), then T(n) = Θ(nlogb a * log n).
3. If f(n) = Ω(nlogb a+ϵ), then T(n) = Θ(f(n)).
ϵ > 0 is a constant.
c) strongly connected (2marks)
biconnected components of a graph (2 marks)

d) Any four points-4 marks


Dynamic Programming Greedy Method

1. Dynamic Programming is used to obtain 1. Greedy Method is also used to get the
the optimal solution. optimal solution.

2. In Dynamic Programming, we choose at 2. In a greedy Algorithm, we make whatever


each step, but the choice may depend on choice seems best at the moment and then solve
the solution to sub-problems. the sub-problems arising after the choice is
made.

3. Less efficient as compared to a greedy 3. More efficient as compared to a greedy


approach approach

4. Example: 0/1 Knapsack 4. Example: Fractional Knapsack

5. It is guaranteed that Dynamic 5. In Greedy Method, there is no such


Programming will generate an optimal guarantee of getting Optimal Solution.
solution using Principle of Optimality.

e) Warshalls algorithm- 2 marks


Example -2 marks

II. Graph reprentation- 4 marks


Graph traversal – 6 marks

III. T(n)=2T(n/2)+n2 by Masters theorem (2 marks)

T(n)=8T(n/2)+n3 by Masters theorem (2 marks)


T(n)=T(n/2)+1 by Masters theorem (2 marks)
T(n)=T(n-1)+n by using recurrence method (4 marks)
IV. Optimal binary search tree solution- 10 marks

V. Dynamic programming approach of Matrix chain multiplication solution- 10 marks.

You might also like