Академический Документы
Профессиональный Документы
Культура Документы
I
I
I73.27try
Solved Question Papers ;i:
Ee- 18 l: s. ll-oali
r:: apolap u
p minirn -,mn E:;OfaJ alE
06cs62 := *r:!s ]o s€
ET:
[1 16! u);i]Al 3O
s.
7ex. 1Ser3iliii
Fourth Semester B.E. Degree Examination, Dec-Jan z: ai:8utf,d
:.1-3o1ei
:--s P oi pal
r -tl0- Ses 2008-2009 Analysis and Design of Algorithms I u o l-,,n auop A,
Time: 3 hrs Max. Marks: 100 )S a..1i iaAO
t
Note: 1. Answer any FIVE full questions, selecting at least TWO questions from each parl :auEeiu 1o e
-+--= < 'r-rprr!
rli"r:_
A and part B.
u. a-i:Jel o'
r aaD,rjqlal a
r f.'ac,ouq:at
PART A he q:iur. sa
.
=nbtuq-1
s,arlepe at
I ' dt.l15:iir
a. Discuss the various stages of algorithm design and analysis process using flow chart.
A{ io uol}e
(10 Marks) -3-"-ut-:-:tY:
b. Explain important fundamental problem types of different categories. (10 Marks) , . rilc.r.-lai0Ja
( p: sttcrt ,<3c
2
ulal uAri.!1
a. Explain in brief the basic asymptotic efficiency classes. (06 Marks) lir:39 qlns,
b. Explain the method of comparing the order of the growth of two functions using Lis ;? -ir}?i
d il .i.ru-t1xs
limits. Compare order of growth of following functions (i) log2nand, Ji (ii) (tog2 id !3L ,C laAO P'
n)2 and,log2r?. (09 Marks) '' ha.c, aqi p;
c. Discuss the general plan for analyzingefficiency of non-recursive algorithms. [) -olit3]ap
lr oeseq sant
(05 Marks) ! Idl s!'.['t/Y
J
?eu Plel frla
' 3*r,*q ale sPl
a. What is brute-force method? Explain sequential search algorithm with an example. e- aqr Aq pallt
Analyse its efficiency. (10 Marks) rer aql}e'l] ur,
b. Write the merge sort algorithm and discuss its efficiency. Sort the list E, X, A, M, p, s 3r-,li::rua dq
.elep rl1
L, E in alphabetical order using merge sort. !F :r
(10 Marks) l.'ori sall^aP
4 ,a1,r E S? Si)P
PART B
Fig. 6(a)
b. Solve the following Knapsack problem
programming.
with given capacity W: 5 using dynm
(10 Ma*nm
Item Weight Value
1
2 $12
2 I $10
3 J $20
4 2 $1s
f,ii , :: I"1
So/ved Quesfion papers Q-3 ,{' l{
Eil@
hmil
ru@
lmr
mrl[
fu$
ls,
l * --- -::-:-:
h-.,-:,,';-=-
; -. =
! d c l- *- ,s
1, --,-=-=.
a- ----- -^^-
I -=:=- :-
! ,:l . -- i',
. 2:-' '.=
arhs
: ^^
=^
-- -^
: : _ i- -:
rl:.< "a ' -
=- =
s!-"*:;:
F : ::a: r.:
, s rl--:=l':3
: i; ::: : ;-i:
I
-- _i
hrn-r
rks t
t-o
5--
Zla-rl5-
Analysis and D_esign ofAlgorithms
Solutions for OeclO0S_Jan
2009
PART A
l.
a' The stages of argorithm
design and anarysis-process
RererropageNo. q-rs using flow chart.
b. fA"eE
Imporranrfundamenralproblemrypes
t
sdF.3u;tuI Gli#trr;krlnr
Refer to page No. 17_21 -(gt$il)
2. FD/ Irorrf
a. Basic asymptotic efficiency
classes
Refer to page No. 55
b. Using limits for c orders of growth
Refer to ,u*" *o.o#aring
c. Comparing
(i) Iog2 n and, Ji
Refer page No. 54, example
2.
(ii) (log2 n)2 and.log2n2
n
]fltogr=""
(1og2n_)2has alargerorder
of growth than g(n)
General plan for analyzing.ffiri;;
Refer to page No. 5g_59
;ror_rrrrrriu. algoritfims,
a
J.
Brute-force method definition a. DividE
Refer to page No. 93145
Refert
algorithm with an example Divide_
i:H:ilT[:'i'l and its errciency
Efficiency analysis_Refer
to page No. 4546
lili -
I,
iil _
ry
Solved Question Papers Q-5
EXAMPI-E
irl i,e
AEEI-MPX
4.
a. Divide -and-conquer technique
Refer to Page No. I l7
Divide-and-conquer to find multiplication of integers 2101 and 1130
i-o
ai
t3fiL
*--=-
-llrr
Q-6 Solved euestion papers
PART B
5.
a. Bottom-up heap sort argorithm expranation
with an exampre.
Refer to page No. 213,215116
Efficiency analysis:
Refer to page No. 216
Horspool's algorithm
Refer to page No. 245/246.
searching solution using
It.*
Refer to Answer 5 (c) of June
Horspool,s algorithm
ti"tv iOg-question paper.
6.
Warshall's algorithm
Referto pageNo.272
Finding transitive crosure
of the given graph using warshalr,s
argorithm.
T}
I ilrU
I ,'rf
t:, C
i
Fig. 6 (a)
qbcd
alo o o ll
ulr o 1 ol
.l t o o rl
,Lo o I o_j
Ro: 010
rample 001
010
Rz:
)-o
ithm.
5-!c_-!;
Z i A - - 5 0-
Q-8 Solved Quesfion Papers
a b cd
aft o l ll
no: alr o 1 tl
"lr o I 1l
olr o r rl
Knapsack problem solution using dynamic programming
Refer to Page No. 285, Example 1, Figure No. g.l3
7.
a. Dijkstra'salgorithm
Refer to Pages No. 307 and309
Solving for single source paths problem for the given graph.
Coatl
fflq
rdl
*l
E
i'li'
So/ved Quesfion Papers Q-9 ,tr
$l
d(b,8) e(d,8+2)
f(d,8+6) *l
il
olIta
FtsP4E
il18 iL{F
f(e, I 3) !
ppa{
ilr i, drll q
Eq'm
lurs a
ftJa!ffi
lele5
Shortest path are tr&ai
atob: a1c -)boflength3 -- Ferd
ftffilqii
atoc:aJcoflength2 Smq
a to d: a -) c + b -+ d oflength 8
lsd
I'qr
ld
ato e: a -) c -) b -+ d J e oflength 10
b.
ato f: a -) c -i b + d -J e 9 oflength
Decision trees definition
13
i,f*,
I,r*,
cn Refer to Page No. 366 ht
-eraph.
Decision trees for sorting algorithm [,n,
Refer to Page No. 367-368 F**
Example r{ Pftl
Hr.,r
Refer to Pages No. 3681369, Figure No. 11.2/Figure No. 11.3
h.*
h*
Concepts of P, NP and lrIP complete problems P'r
Refer to Page No. 373-379 FId
u Fqr
b. Back-tracking algorithm instance for subset sum problem using back- hrp
tracking. F"
lE;
Refer to Page No. 398, Figure No. 12.4
Ln,
hlrn
1,,^,
t:
Lrr
f-
Contl I
F
I
!-
g#r EnEaJ&
s{r
Solved Question Papers Algc
USN i
end
06cs62 Set r
the a
PART A
a. Cm
1. the N
Consider the following recursive algorithm for computing the sum of the first n cubes
tr lllll
lfl
d
T
So/ved Question Papers Q-11 il I'L I
I
TI
r based on checking c. Briefly explain how breadth first search can be used to check connectness ofa graph lnE
' (4Marks) and also to find the number of components in a gaph. (6 Marks) 'h,qs
l!,&@ryD
lwrq,
pgftIrr
(6 Marks) fumE IC
PART B
lo aq-
!, n t"*-,
a
Fqtry
a. Design a presorting-based algorithm to find the distance between the 2 closest tst uW
numbers in an array of 'n' numbers. Compare the efficiency of this algorithm with Fe
hxoq
that of brute-force algorithm. (10 Marks)
hp
b. Construct AVL tree for the set of elements 5, 6, 8, 3, 2, 4, 7 . (6 Marks)
' hreq r
c. Apply Horspool's algorithm to search for the pattern BAOBAB in the text BESS F'mn
NEW ABOUT BAOBABS FErnAr
(4 Marks)
h*wq
Also, find the total number of comparisons made. [pmq
sr
frroq
For the input 30, 20, 56,75,31, 19, construct the open hash table. Find largest and
average number of key comparisons in a successful search in the table. (6 Marks)
t-
m lPsPqP
(4 Marks)
fa
b. Explain dynamic programming.
lt
(10 Marks)
l"
m ofthe first n cubes.
H
Et'e =iiEB&
Q-12 So/ved Quesflon Papers
c. Write the lormula to find the shortest path using Floyd's approach. Use
method to solve the following all pairs shortest paths problem. (10 I
[o €
g
3 -l
lz - -l An
l-
tt 7 o 1l s
l6 € 6 0lJ
\'
7.
a. Use Kruskal's method to find min cost spanning tree for the following graph
(6 \[r'il'fxqm a. Algorithm&
b. Prioritl'queri
Prioriq'quer
)essgnding 1
heap largesr
at inder 1 of
requires dele
For example.
0x
b. Write Huffrnan tree construction algorithm.
c. Draw the decision tree for the 3-elements insertion sort.
(8 Nfadsill
(6 ivlarlsill fT*T
8. After delete r
c.
Draw the state space tree to generate first solution to 4-queens problem. with the firm
solution, generate another solution, making use of board's symmetry.
Explain P and NP problems.
(8 Ma*s[
(6 Marlst
[T'T
c. To find ffiD
Asymptotic r
52.
For the
-eir'€r
i. algorith
dia-eoca
ii. basic q
iii. the basii
(- -\f'
L worsst
/-,
:I:={
ir li ill
r1
rfl
l'li '
)i-€l Jf[.tilrfi
PART A s' ;,fl-Br
:E: a-ifrlr
L ;;r-qp ol l
mg graph. Its-rd, ?{JlW
(6 Markst a. Algorithm development process-Refer to Page No. 9-15, Figure No. 1.2. [-]s 3nl+ .lE
b. Priority queue implementation as unsorted array-Refer to Page No. 26. ::a5eur g
Priority queue can be implemented efficiently using heap data skucture. e-; 3 s ]l*trf
a*: a".lr"s&
Descending priority queue can be implemented using max heap. In a max
U ar'rbixulrr
heap largest element (element with highest priority) can always be found r'.ri,o, orup
at index 1 of the array. Hence, the delete operation of the priority queue lc€ r.+ilur
requires deletion of the element at index 1. q se]|:orruqp
l s/ar0W
For example, consider the heap dt8g:
Ftl lo uq
(8 Marks)
0r234
, 3rltlll,tllll,t
10 9 8 5 6 7 3
(6 Marksl f1u-:caP
p.; rrr**,
After delete operation, the heap looks like F t'; t*
lm. (6 Marks) )n-'::erp
gm. With the first
0123456 h-- ru -,,
fro Srrurur
(8 Marks) 9 6 8 5 J 7
ry-- iear, ,olm
(6 Markst bq",c4 eq
c. To flnd GCD (60, 2$by applying Euclid's formula-Refer to Page 4-5. f :t -,oqre
2. o*""w
fo"
Xdlqut
a. Asymptotic notation used in algorithm analysis-Refer to Page No. 50- Fr
pef
feaU
52.
iar.'o
b. For the given algorithm be- a; "*
mq
tur
i. algorithm checks if the given rnatrix is symmetric over the main "oaw
a-.=au
frs
diagonal.
Pc - wen
ii. basic operation is comparison lr:,, sm
iii. the basic operation is executed (in the worst case) f==qw
l-*
'
cLworssl
-.:I"-2Yn-t I har
Li=O L.i_i+t'
-#
: Xt,, - t) - (i +.1) + 1l
t=(,
H
tr-:
-;a StEEs
Q-14 Solved Quesfrbn papers
Q-15 So/vedeues
: Ia-r-i) _N
i=0 _h{
_M
: Ii=Jr,-,r-I,=^" when I::
-l
I
:(n-l)
Ir-I'
i=0 i=0
_I
_,
-[
:(n- l)[(n-2)-0+ rr- M(n) -3
[E:zler] a
J.
e0
:(n-1)(n-l)- (n-2)(n-l)
a. Quick smr
euick sat
:(n-rtlrn-l;-(n-zl1 b. Algoriilm
L' 2.l c. Exhausiw
:(n- qlzn-z-n+21 +.
a.
Lzl Inasetofl
comparisu
:(n-1) /l) i. keyno
\2)
I
ii. sorer
The averagl
_ n(n-l)- (n')
. ,. i. Sm
,
C-E
: l" n2e{n2)
1
iv. The efficiency class is quadratic.
v. The algorithm can be further improved. ii. Unq
For the given recursive argorithm to compute the sum C,E
of first n cubes, the
basic operation is multiplication. Let M(n) be the
number of times the
basic operation is executed. Then
M(n):M(n-l) +1+l+l forn> I b. DFS algmirt
to cumpute to multiply S(n_l) c, Applicatimr
S(n-l) bynrn*n
M(l):0
Solving the relation, we have
M(n):M(n-l)+3
5.
= [M(n *2)1+Z+S
: M(n - 2)+3+3 Presorting{c
: [M(n - 3)+3]+3+3 numbers in a
brute-forec at
Q-14 Solved Quesfrbn papers
Q-15 So/vedeues
: Ia-r-i) _N
i=0 _h{
_M
: Ii=Jr,-,r-I,=^" when I::
-l
I
:(n-l)
Ir-I'
i=0 i=0
_I
_,
-[
:(n- l)[(n-2)-0+ rr- M(n) -3
[E:zler] a
J.
e0
:(n-1)(n-l)- (n-2)(n-l)
a. Quick smr
euick sat
:(n-rtlrn-l;-(n-zl1 b. Algoriilm
L' 2.l c. Exhausiw
:(n- qlzn-z-n+21 +.
a.
Lzl Inasetofl
comparisu
:(n-1) /l) i. keyno
\2)
I
ii. sorer
The averagl
_ n(n-l)- (n')
. ,. i. Sm
,
C-E
: l" n2e{n2)
1
iv. The efficiency class is quadratic.
v. The algorithm can be further improved. ii. Unq
For the given recursive argorithm to compute the sum C,E
of first n cubes, the
basic operation is multiplication. Let M(n) be the
number of times the
basic operation is executed. Then
M(n):M(n-l) +1+l+l forn> I b. DFS algmirt
to cumpute to multiply S(n_l) c, Applicatimr
S(n-l) bynrn*n
M(l):0
Solving the relation, we have
M(n):M(n-l)+3
5.
= [M(n *2)1+Z+S
: M(n - 2)+3+3 Presorting{c
: [M(n - 3)+3]+3+3 numbers in a
brute-forec at
:)r !;J
tll; e
Q-15 Solved Quesfron Papers
: M(n- 3)+3+3+3
Solved Question Papers Q-f 5
1,: :u
t "fft
: M(n - 3)+3*3
: M(n- i)+3*i ul si ll-c-!
c: l, apolaP t
whenl:n-1 pegJoFJ a.ii
: M(n{n-l))+3*(n-1) :lre Llns lo s
: M(1)+3*(n-1) Llol dli:.i,lt a
s ii-3o1t
:613*1n_l)
IeE ar:: Butr{t
M(n) :3n-3 lciLsrp oi Pe
e 0(n) laL",r, aUOP J
i'>s a.;: lau
\ '0
tt
t :au3eu-.r 10 ,
u'ktg
i
5. i rlm
a. Presorting-based algorithm to find the distance between the 2-closest , !fr.4il
tfe 3;E
Q-16 Solved Question PaPers
return mi-ndist
worst cast efficiencY is
T(n)-T.on(n)+T..-(n) 19:
e O(nlog n) + 0(n)
e O(nlog n)
g(n2)'
The efficiency ofbrute-force algorithm is
The loc
o("= l)
This is because there will u" number of comparisons.
' 2-
This clearly shows that preorder-based algorithm is more efficient
compared to the brute-force algorithm to find the minimum distance.
b. All tree construction for the set of elements 5, 6, 8, 3,2,4,7-Refer to
Page No. 207. Key m
c. Horspool's algorithm to search the pattern BAOBAB in the given text
Shift table
Chracter (c) A B C o Z
Shift t(c) I 2 6 6 3 6 6 6
b. Dynn
c. Ford
275-
Soh*io
Kru&
Li$rL
6.
To construct open hash table for the input 30, 20, 56, 76, 31, 19 lE6
Assumption: Let the hastr function be lw"tr
4
h(k): (sum of digits of k)mod l0 lr"t-rl
h(30):(3+0) mod lO: 3 lr*,*r
J
l[r
I
{
So/ved Question PaPers Q-17 l# )
t
I
h(20) =(2+0) mod l0:2
h(s6):(s+6) mod 10: 1 ::: apoFP
h(75):(7+5) mod 10:2 la3;C]a, ar€
L;3-:l3sl o
A an!'iiL.Fli
-/:5c'oLiula]
19 56 20 30 31
lxa qriil'n sa'
T .5.$aDiliqfal'
Sr?)l)PlfP fl'-
75 dr.i15:1'
The load factor = A: nlm )iA Io rlollE
Total number of keYs : ;- ;ri,qr,:
I i!.c+ JeSOr
Total number of cells ffi<
fficient fc:soa,u
De- : 6 :0.6: 60% , ' i -:::
P"''=e qcms
,aun
Refer to 10
i^--s :a iYe
Key comparisons in successful searches
is io :, 'rurPr
i' '*
i
7.
Kruskal,salgorithmtofindthecostforthegivengraph. dp b*J
a.
List the edges in a sorted order' itm
i ,rrsn
be cd de cf bf
Edges ab bc ef af ce
7 8 9 10 11 t3 l4 20
Weieht 6 7
x x x x
Invertion status
4 5
lnversion order I z -')
f;fB 3,n I is
Q.18 So/ved Quesfbn papers
USN
I-fIl-
06cs63
Total cost:39
b. Huffinan tree conskuction algorithm-Refer
to page No. 31r-312.
Fourth S
c.
l;:*t*
tree for 3-elements invertion sort-Referto page
No. 369, Figure 200y
Time: 3 hrs
8.
Note: 1. Ansm
a. Difference between back hacking and branch-and-bound
argorithm.