B.Tech DEC 2022 COM CSPC-21 SEM 3

You might also like

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

B.

Tech Co 3rd Semester Dec 2022


CSPC 2l Design & Analysis of Algorithms
Time:3 hours Total Marks: 50
Note: l' Attempt complete PART A on consecutive pages separately.
Similarly attempt pART B
separately. Answers for pART A must not be mixed wiin panr
B ai all.
2' If you develop some programs using some special logic, provide necessary
com ment/explanation for that.
3' while writing any module/function, if it calls any other function, also write
the code of that
function' If your code uses some structures and ghlal variabtes, define
those also. Use of STL,
APIs is not allowed. coding should use c languagi related syntax.
4' In all programming oriented question., of the algo & modularity wil also be a
"fii"i.n"y
criteria of evaluation along with the correctness.
5. Attempt one out of Ql and e2. similarly attempt one out
of es and e6.
6'T"hi.nk.loeicallv. Coqgpp.ts/algos/notations.described in vour tex,t book
of A ithms U;e.to- b_c,
u sed,jwhersyer u nspecified.

PART A (ATTEMPT SEPARATELY without mixing wirh pART B)

1. (a) Define Master Theorem and solve recurrence relation a T


@12)+ n2 using Master Theorem. 5
(b) Assume that QuickSort is implemented using the logic given in
Coimen,s book. Tell with
explanation the average case time complexity oi the
Qulck iort. There is no need to write the
code' Now sort the following data using it, and show values for each
main step (main step means
an element/pivot reaching to its correct position): 6, 4, 10, I g, 20,
15,3,7, 17 5
OR
) (a) Using recurrence tree, find time complexity of 4 T (n/3) +
(b) Tell with explanation the worst case time complexity
3n 5
of the MergeSort. There is no need to
write the code. Now sort the following data using ii, and show values for each main
step:
75.15,45,25,65,35,5,55 5

3. (a) In context of hashing. defirre (i) collision


iii) prirnary,clustering l
(b) write pseudo code/function in c fbr insertiorr in lliriar,v Search 'l.ree.
(c) Assume alphabets (A,B.C,D,E) have f,requencies 12, -t0, 9, 5. 24 -l
respectively. Appll l lLrlllr,,
coding algo on this and show all steps of Huffman tree generation. Then
show the Fluflhan c.t1e
generated for each alphabet. No need to write the code/algo.
I
4. rvrr*! rr
\s.,, What is IPriority
rrvrrtJ Yusutr,
f) List the
Queue? Lrbl [Ile operallons
operations allOWeO
allowed On it. LlSt
on tt. List ttS
its 2 appliCatiOnS.
applications. J
Explaii b-.'-"^t yl",^r normally the range of values for its inpur? 3
(c) :::.:::oI::-::rks?
t:l Show all main steps to generate MST of the following graph us--ing prim's
J

Algo (there is no
need to write the code): q'^4
PART B (ATTEMPT SEPARA'I FILY w,ithout mixins with I,Alt't A1
\OTE: Attempt QS if 1,ou want to scorefull 20 marks. ln case-|tou clun,t know,the unsw,ets <t/ eS,
you con ottempt Q6, but then you will be able lo score mox 13 marks, not 20. Don't attemp bollt.
5. (a) Consider the following B-Tree of degree t=2. Shor1,. B 'free after insertion of following values
one by one: 8, 30. 100, 75,25.
ffif
rg:n1 ru 4z 1t 7s

(b) Assr-rme that all edges of a directed graph are stored as an array o1'structures having
{star1*v.
end-v, weight). Write a function in C with proper parameters to generate nvo arra),s trom ihc
given input array: (i) array of all loop-edges i.e. which are pointing to itself (ii) find thc verlcr
having highest weighted outgoing edge & generate an array clf edges oLrtgoing fitnr rhis vcrre\. i
(c) Assume that the activity selection problern is to be solved using Dynamic Programming.
(i) Write its recursive solution using optimal substructure (write mathematically / C-f unction)
(ii) write a function in C for its bottom up DP solution. You can use global variables.
s
(d) Consider the following code for the graph-coloring backtracking-problem using m colors.
Write the pseudo-code/function in C for nextvalue(..) function. s
void mColoring(int k)
{do
i iiextr.aluc(k) ; if (! :{[l<] ) break;
if ( k =: n) printresult0;
else mColoring(k+l); )
OR
(a) Assume that the input graph is directed and is stored using adjacency list. Write a function in C
which generates the equivalent adjacency matrix for the given ad.iacency-list based graph.
compute its time complexity and give two lirre explanation lor the same. 3
(b) Consider the fbllowing B-Tree ol'degree F3. Slror.v B 'l"rcc alicr inscrtiurr ol' lilllorr irru virlttcs
*!

one by one: C, Y, K, E, F J

(c) Write a function in C or pseudo-code to find solution of N-Queen p.oLlem. Use of 2-d alay
is not permitted. You can use l-d array. 3
(d) Prove the followirrg Theorem of LCS problem of Dynamic programming: 4
Let X : (x 1,x2,...Xn,) and Y : (y,, y2, y3,.... yr) be sequences, and let Z : (zr, 22,...2p) be
any LCS of X and Y.
1. If xr: y,,, then Zk: Xrr: yn. and Z1_1 is an LCS of Xn,-1 and y,,_1.
2. If x,, !: y,, then z1 !: x,n implies tl-tat l, is an LCS ol'X,,,_s and y.
3. If xn, !: yn, then zp !: y,, implies lhat Z is an I_CS ot'X and y,,-1.

You might also like