Set C: Department of Information Technology (Academic Year - 2018-19) Unit Test - I
Set C: Department of Information Technology (Academic Year - 2018-19) Unit Test - I
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
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
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.
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
-----------******-----------