Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Pune Institute of Computer Technology, Pune-43

DEPARTMENT OF INFORMATION TECHNOLOGY


(Academic Year – 2018-19)
UNIT TEST - I
Subject : Design and Analysis of Algorithms Subject Code : 314452
Class : TE (IT) Div: TE 9 [ Max. Marks: 30]
Date : 15/02/2019 Day: Friday Duration : 1 Hour

Instructions to the candidate: Roll No: -


1. All questions are compulsory.
SET C
2. Assume suitable data, if necessary.

M
a
x
Ques.
Question M
No.
a
r
k
s
Define following terms
1-a a) Theta b) Little Oh c) Little omega 5
d) oh e) omega
long power (long x, long n) {
if (n==0) return 1;
if (n==1) return x;
1-b 5
if ((n % 2) == 0) return power(x,n/2) * power(x,n/2);
else return power(x,n.2) * power(x,n/2) * x }
Write down recurrence Relation for above snippet? And Find the Time Complexity.
T(n)=2 T(n/2) + c if n is even
T(n)=2 T(n/2). x +c if n is odd
T(n)=1 n=0
Sol:- T(n)=x n=1

Time Complexity= O(n)


Let n=3, and (L1, L2, L3)=(5,10,3) find the optimal ordering on tapes using greedy
2-a 5
Method.

Ordering d(I) Result

1 123 5 + (5 + 10) + (5 + 10 + 3) = 38 38/3=12.66

2 132 5 + (5 + 3) + (5 + 3 + 10) = 31 31/3=10.33


Sol:-
3 213 10 + (10 + 5) + (10 + 5 + 3) = 43 43/3=14.3

4 231 10 + (10 + 3) + (10 + 3 + 5) = 41 41/3=13.33


5 312 3 + (3 + 5) + (3 + 5 + 10) = 29 29/3=9.66
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2018-19)
UNIT TEST - I

6 321 3 + (3 + 10) + (3 + 10 + 5) = 34 34/3=11.33

Optimal Solution is=3 , 1, 2

find out minimum cost spanning tree using Prim’s algorithm for given graph:
Edge Cost Edge Cost Edge Cost
(a, b) 3 (b, f) 4 (f, d) 5
2-b (a, f) 5 (c, d) 6 (f, e) 2 5
(a, e) 6 (c, f) 4 (e, d) 8
(b, c) 1

(a, b), (b, c), (b, f), (f, e), (f, d) =3+1+4+2+5

3-a Compare Greedy approach and Dynamic programming. 2

Greedy Dynamic Programming

A greedy algorithm is one that at a Dynamic programming can be thought of


given point in time, makes a local as 'smart' recursion., It often requires one
optimization. to break down a problem into smaller
components that can be cached.

Greedy algorithms have a local choice Dynamic programming would solve all
of the subproblem that will lead to an dependent subproblems and then select
optimal answer one that would lead to an optimal solution.

Sol:- A greedy algorithm is one which finds A Dynamic algorithm is applicable to


optimal solution at each and every problems that exhibit Overlapping
stage with the hope of finding global subproblems and Optimal substructure
optimum at the end. properties.

More efficient as compared, to Less efficient as compared to greedy


dynamic programming approach

Example Example
Pune Institute of Computer Technology, Pune-43
DEPARTMENT OF INFORMATION TECHNOLOGY
(Academic Year – 2018-19)
UNIT TEST - I
Find the shortest path to each vertex from vertex 0 (s) using bellman ford algorithm.

3-b 8

0 1 2 3 4 5 6 7
0 0 ∞ ∞ ∞ ∞ ∞ ∞ ∞
1 0 5 ∞ ∞ 9 ∞ ∞ 8
2 0 5 15 20 9 13 29 8
3 0 5 14 18 9 13 26 8
4 0 5 14 17 9 13 25 8
Sol:- 5 0 5 14 17 9 13 25 8
6 0 5 14 17 9 13 25 8

So, the distance from node 0 (S) to each node is:


0→1=5
0→2=14
0→3=17
0→4=9
0→5=13
0→6=25
0→7=8

-----------******-----------

You might also like