Solved Question Papers - · PDF fileAnswer any FIVE full questions, ... Explain important...

19
I I I I I I73.27try Ee- 18 p minirn -,mn ET: [1 7ex. 1Ser3iliii r -tl0- Ses t Solved Question Papers 06cs62 Fourth Semester B.E. Degree Examination, Dec-Jan 2008-2009 Analysis and Design of Algorithms Time: 3 hrs Max. Marks: 100 Note: 1. Answer any FIVE full questions, selecting at least TWO questions from each parl A and part B. PART A I a. Discuss the various stages of algorithm design and analysis process using flow chart. (10 Marks) b. Explain important fundamental problem types of different categories. (10 Marks) 2 a. Explain in brief the basic asymptotic efficiency classes. b. Explain the method of comparing the order of the growth limits. Compare order of growth of following functions (i) n)2 and,log2r?. c. Discuss the general plan for analyzingefficiency of non-recursive algorithms. (05 Marks) J a. What is brute-force method? Explain sequential search algorithm with an example. Analyse its efficiency. (10 Marks) b. Write the merge sort algorithm and discuss its efficiency. Sort the list E, X, A, M, p, L, E in alphabetical order using merge sort. (10 Marks) 4 a. What is divide-and--conquer technique? Apply this method to find multiplication of integers 2101 and 1130. (0g Marks) b. Explain the differences between DFS and BFS. Solve topological sorting problem using DFS algorithm with an example. (l?Marks) ;i: (06 Marks) of two functions using log2nand, Ji (ii) (tog2 (09 Marks) l: s. ll-oali r:: apolap u E:;OfaJ alE := *r:!s ]o s€ 16! u);i]Al 3O s. :.1-3o1ei z: ai:8utf,d :--s P oi pal I u o l-,,n auop A, )S a..1i iaAO :auEeiu 1o e - = < 'r-rprr! +-- rli"r:_ u. a-i:Jel o' r aaD,rjqlal a r f.'ac,ouq:at he q:iur. sa =nbtuq-1 . s,arlepe at ' dt.l15:iir A{ io uol}e -3-"-ut-:-:tY: , . rilc.r.-lai0Ja ( p: sttcrt ,<3c ulal uAri.!1 lir:39 qlns, Lis ;? -ir}?i d il .i.ru-t1xs i d !3L ,C laAO P' '' ha.c, aqi p; [) -olit3]ap lr oeseq sant ! Idl s!'.['t/Y ?eu Plel frla ' 3*r,*q ale sPl e- aqr Aq pallt rer aql}e'l] ur, s 3r-,li::rua dq !F :r .elep rl1 l.'ori sall^aP ,a1,r E S? Si)P

Transcript of Solved Question Papers - · PDF fileAnswer any FIVE full questions, ... Explain important...

Page 1: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

I

I

I

I

I

I73.27try

Ee- 18

p minirn -,mn

ET:

[1

7ex. 1Ser3iliiir -tl0- Ses

t

Solved Question Papers

06cs62

Fourth Semester B.E. Degree Examination, Dec-Jan2008-2009 Analysis and Design of Algorithms

Time: 3 hrs Max. Marks: 100Note: 1. Answer any FIVE full questions, selecting at least TWO questions from each parl

A and part B.

PART A

I

a. Discuss the various stages of algorithm design and analysis process using flow chart.

(10 Marks)b. Explain important fundamental problem types of different categories. (10 Marks)

2

a. Explain in brief the basic asymptotic efficiency classes.b. Explain the method of comparing the order of the growth

limits. Compare order of growth of following functions (i)n)2 and,log2r?.

c. Discuss the general plan for analyzingefficiency of non-recursive algorithms.(05 Marks)

J

a. What is brute-force method? Explain sequential search algorithm with an example.Analyse its efficiency. (10 Marks)

b. Write the merge sort algorithm and discuss its efficiency. Sort the list E, X, A, M, p,L, E in alphabetical order using merge sort. (10 Marks)

4

a. What is divide-and--conquer technique? Apply this method to find multiplication ofintegers 2101 and 1130. (0g Marks)

b. Explain the differences between DFS and BFS. Solve topological sorting problemusing DFS algorithm with an example. (l?Marks)

;i:

(06 Marks)of two functions using

log2nand, Ji (ii) (tog2

(09 Marks)

l: s. ll-oalir:: apolap uE:;OfaJ alE

:= *r:!s ]o s€

16! u);i]Al 3O

s. :.1-3o1ei

z: ai:8utf,d:--s P oi pal

I u o l-,,n auop A,

)S a..1i iaAO

:auEeiu 1o e

- = < 'r-rprr!+-- rli"r:_

u. a-i:Jel o'r aaD,rjqlal a

r f.'ac,ouq:athe q:iur. sa

=nbtuq-1 .

s,arlepe at' dt.l15:iir

A{ io uol}e

-3-"-ut-:-:tY:

, . rilc.r.-lai0Ja( p: sttcrt ,<3c

ulal uAri.!1

lir:39 qlns,Lis ;? -ir}?id il .i.ru-t1xs

i d !3L ,C laAO P'

'' ha.c, aqi p;[) -olit3]aplr oeseq sant

! Idl s!'.['t/Y?eu Plel frla

' 3*r,*q ale sPle- aqr Aq pallt

rer aql}e'l] ur,

s 3r-,li::rua dq

!F :r .elep rl1

l.'ori sall^aP,a1,r E S? Si)P

Page 2: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

Q-2 Solved Question papers

PART B

a' Explain bottom-up heap sort algorithm with an example. Anaryse its efficienq,"-

b. Write Horspool,s ulg:llh- Apply Horspool algorithm to search ,", [].: ffiBAOBAB in the text BESS_KNEw_agour_ga6eaBA. - (lol\{adu#

a. write warshail's algorithm. Appry warshafl,s argorithm to find the transitive crorcof the following Fig. No. 6(a) - - "-Dv'^r,t rv rurl

(10 Meffi

b. Solve the followingprogramming.

Fig. 6(a)Knapsack problem with given capacity W: 5 using dynm

(10 Ma*nmItem Weight Value

1 2 $12

2 I $103 J $204 2 $1s

write Dij^kstra's algorithm and apply the same to find single sourceproblem for the following gaph taidng vertex ,a,as source?, fig. N".shortest pette7(a).

(10 Ma*st

what are decision trees? Explain the concept of decision trees for sorting algorithmswith an example' r- -^ YYvrsrv'trvvD rt'r (10 Marks)

Page 3: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

ll l1 rl

,l 'tt

f,ii , ::,{' l{

I"1

mrl[fu$

ftuNil

Eil@

hmil

ru@

lmr

arhs

rl:.<

hrn-r

rks t

So/ved Quesfion papers Q-3

a. Briefly explain the concepts of P, NP and NP complete problems. (10 Marks)b. Explain back-tracking algorithm. Apply the same to solve the following instance of

the subset*sumproblem: S : {3, 5, 6,7} and d : 15 (10 Marks)

ls,

l * --- -::-:-:h-.,-:,,';-=-

; -. =

! d c l- *- ,s

1, --,-=-=.a- ----- -^^-I -=:=- :-

! ,:l . -- i',. 2:-' =^ '.=

: ^^ - - -^: : _ i- -:

=- = "a ' -

s!-"*:;:F : ::a: r.:

, s rl--:=l':3: i; ::: : ;-i:

I

-- _i

5--Zla-rl5-

t-o

Page 4: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

l.

Analysis and D_esign ofAlgorithmsSolutions for OeclO0S_Jan 2009

PART A

a' The stages of argorithm design and anarysis-process using flow chart.RererropageNo. q-rs fA"eE t sdF.3u;tuI Gli#trr;krlnrb. Imporranrfundamenralproblemrypes -(gt$il)Refer to page No. 17_21 FD/ Irorrf

a. Basic asymptotic efficiency classesRefer to page No. 55b. Using limits for c

Refer to ,u*" *o.o#aring orders of growth

c. Comparing

(i) Iog2 n and, JiRefer page No. 54, example 2.

(ii) (log2 n)2 and.log2n2

fi^(lrg, O: - [kos, nz)]t _ Y*'* log2 n' flog, n2lt - g : Iog n

]fltogr="" n

(1og2n_)2has alargerorder of growth than g(n)General plan for analyzing.ffiri;; ;ror_rrrrrriu. algoritfims,Refer to page No. 5g_59

Brute-force method definitionRefer to page No. 93145

i:H:ilT[:'i'l algorithm with an example and its errciency

Efficiency analysis_Refer to page No. 4546

2.

aJ.

a. DividERefertDivide_

Page 5: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

b.

Solved Question Papers Q-5

Merge sort algoritl'rm, efficiencyRefer to Page No. 119-120Sorting the list E X A M P L E in alphabetical order using merge sort

Divide -and-conquer techniqueRefer to Page No. I l7Divide-and-conquer to find multiplication of integers 2101 and 1130

I, lili -iil _ ry

irl i,e

4.

a.

i-o

EXAMPI-E

AEEI-MPX

ai

t3fiL *--=--llrr

Page 6: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

Q-6 Solved euestion papers

2101 * ll30 :2374130

Ql * tl) rc4 e2 * 4t _26D rc2

{2* Drcz (3*2=3_)to (I*t) (o * 3) 102 (1 * 3 _ 0) 10 (t*o)

Q*qrc2 (4*5-10)10r (2*l)

Difference between DFS and BFSRefer to page No. 161Solving topological lofl_nqnrobrem using DFS algorithm with an exampleRefer to page No. rc,q;lrc5,ftg"* N;. ;.;

5.

PART B

Bottom-up heap sort argorithm expranation with an exampre.Refer to page No. 213,215116Efficiency analysis:Refer to page No. 216Horspool's algorithmRefer to page No. 245/246.

It.* searching solution using Horspool,s algorithmRefer to Answer 5 (c) of June ti"tv iOg-question paper.

Warshall's algorithmReferto pageNo.272Finding transitive crosure of the given graph using warshalr,s argorithm.

a.

6.

+

01 *30

Page 7: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

Fig. 6 (a)

So/yed Question papers e-z

T}I ilrU

I ,'rf i

lt:, C

)-o

qbcdalo o o llulr o 1 ol.l t o o rl,Lo o I o_j

rample

Ro:

Rz:

010001010

ithm.

5-!c_-!;Z i A - - 5 0-

Page 8: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

Q-8 Solved Quesfion Papers

a b cdaft o l ll

no: alr o 1 tl

"lr o I 1l

olr o r rlKnapsack problem solution using dynamic programmingRefer to Page No. 285, Example 1, Figure No. g.l3

7.

a. Dijkstra'salgorithmRefer to Pages No. 307 and309Solving for single source paths problem for the given graph.

Tree vertrics Remaining vertics Illustration

a(-, 0) B(a,4), c(a,2), d (-, -), e(-, -),f(-, -) a.,\o

c(a,2) b(a, 2+l), d(c, 2+8), e(c, 2+10),f(-, -)

b(c, 3) d(b, 3+5), e(c, 12)f(-, -)

Coatl

Page 9: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

fflqrdl *l

$l*lilolItaFtsP4E

il18 iL{F

rflD qN

!ppa{drll qEq'mlurs a

ftJa!ffilele5tr&ai

Ferdftffilqii

SmqlsdI'qrldf*,i,I,r*,ht[,n,F**

PftlHr.,rh.*h*P'rFIdFqrhrpF"lE;Ln,hlrn1,,^,

t:Lrr

f-II

F!-

ilr i,

--

r{

u

J

b.

i'li' E

,tr

cn -eraph.

So/ved Quesfion Papers Q-9

Shortest path are

atob: a1c -)boflength3atoc:aJcoflength2a to d: a -) c + b -+ d oflength 8

ato e: a -) c -) b -+ d J e oflength 10

ato f: a -) c -i b + d -J e 9 oflength 13

Decision trees definitionRefer to Page No. 366

Decision trees for sorting algorithmRefer to Page No. 367-368ExampleRefer to Pages No. 3681369, Figure No. 11.2/Figure No. 11.3

Concepts of P, NP and lrIP complete problems

Refer to Page No. 373-379b. Back-tracking algorithm instance for subset sum problem using back-

tracking.Refer to Page No. 398, Figure No. 12.4

d(b,8) e(d,8+2)f(d,8+6)

e(d, 10) f(e, 10+3)

f(e, I 3)

Contl

g#r EnEaJ&

Page 10: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

Solved Question PapersUSN

06cs62

June-July 2009 Analysis and Design of AlgorithmTime: 3 hrs Max. Mar*s;

Note: 1. Answer any FIVE full questions selecting at least TWO questions from each

1.

PART A

a. With figure, explain algorithm development process. (10lv{affirb. Explain how priority queue can be implemented as unsorted anay. (6 Mffirc. Find GCD (60, 2\ by applying Euclid's forrnula. Estimate the number of -- -

computation is done in Euclid's method and in an algorithm based on che*i;consecutive integers from min (m, n) down to gcd (m, n). (4Mary

a. Explain all asymptotic notations used in algorithm analysis. (6 MadNil

b. Consider the following algorithm

Algorithm Enigma (A[0.. n 1, 0.' n 1])for I -+ 0 t-o n-2 do

F^- : / i+1 to n-1 do!v! J \

if A[i, jl + Alj, ilreturn fafse

end forend for

return trueend algorithm

i. What does this algorithm compute?

ii. What is its basic operation?

iii. How many times is the basic operation executed?

iv. What is the efficiency class of this algorithm?

v. Can this algorithm be further imported? (10 Marksl

Consider the following recursive algorithm for computing the sum of the first n cubes

I Fourth Semester B.B. Degree Examination,

2.

s{rAlgc

i

end

Set rthe a

J.

a. Writ

b. Writc. Ord

a. Cmthe N

the ruu[

b. wdtc. Brid

and:

a. Desinud.hatr

b. Cmc. Ad

NEU

Also

a. ForilaveE

b.Expl

6.

Page 11: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

So/ved Question Papers Q-11

s (n) : 13 + 23 + 33 + ... + .,'Algorithm S (n)

if (n : 1) return 1

efse return (S (n*1) + n* n* n)

end alqorithm

Set up and solve a recurrence relation for the number of times the basic operation ofthe algorithm is executed. (04 Marks)

a. Write the quick sort algorithm. Trace the same on data set 5, 3, 1, 9, 8, 2,4,7.

Write an algorithm to find the height of binary tree.

(10 Marks)(4 Marks)

Outline an exhaustive search algorithm to solve a travelling salesman problem.(6 Marks)

Consider a set of 13 elements in an array list. State the elements of array that require

the largest number of key comparisons when searched for by binary search. Findthe average number of key comparisons made by search in successful search and

tr llllllfl

dil I'L

TI

f,II

TI

Iwqrlo1]llraFpep@$E rFrElr@r{B{

sl] Il"Fpeflldruryto

ri, lSqm{hp amUoufu4eqIfqtilar#haqr

- lxequh*nmiruIsryl4{l,n P"I

lnEl!,&@ryD'h,qslwrq,pgftIrrfumE IClo aq-

!, n t"*-,Fqtry atst uWFehxoqhp

' hreq rF'mnFErnArh*wq[pmqfrroq

sr

m lPsPqPt-faltl"H

nation,\lgorithms

trt{ax. Marks: 100

irms from each Part-

(10 Marks)

ty. (6 Marks)

p number of times

r based on checking' (4Marks)

(6 Marks)

(10 Marks)

m ofthe first n cubes.

b.

c.

4.

b.

c.

unsuccessful search in this array.

Write depth first search algorithm.

Construct AVL tree for the set of elements 5, 6, 8, 3, 2, 4, 7 .

Apply Horspool's algorithm to search for the pattern BAOBAB in the

NEW ABOUT BAOBABSAlso, find the total number of comparisons made.

For the input 30, 20, 56,75,31, 19, construct the open hash table. Findaverage number of key comparisons in a successful search in the table.

Explain dynamic programming.

(6 Marks)(8 Marks)

(6 Marks)text BESS

(4 Marks)

largest and(6 Marks)(4 Marks)

a.

b.

c.

Briefly explain how breadth first search can be used to check connectness ofa graph

and also to find the number of components in a gaph. (6 Marks)

PART B

Design a presorting-based algorithm to find the distance between the 2 closest

numbers in an array of 'n' numbers. Compare the efficiency of this algorithm withthat of brute-force algorithm. (10 Marks)

b.

=iiEB&Et'e

Page 12: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

Q-12 So/ved Quesflon Papers

to find the shortest path using Floyd's approach.

following all pairs shortest paths problem.

Write Huffrnan tree construction algorithm.

Draw the decision tree for the 3-elements insertion sort.

a. Differentiate between back tracking and branch-and-bound algorithm.

b. Draw the state space tree to generate first solution to 4-queens problem.

solution, generate another solution, making use of board's symmetry.

c. Explain P and NP problems.

c. Write the lormulamethod to solve the

[o € 3 -llz g - -ll- 7 o 1lttl6 € 6 0l

\' J

Use(10 I

(8 Nfadsill(6 ivlarlsill

(6 Ma*stlwith the firm

(8 Ma*s[(6 Marlst

Algorithm&Prioritl'queriPrioriq'quer)essgnding 1

heap largesrat inder 1 ofrequires dele

For example.

Asymptotic r

52.

For the -eir'€ri. algorith

dia-eoca

ii. basic qiii. the basii

(- -\f'L worsst /-,

:I:={

Ans

7.

a. Use Kruskal's method to find min cost spanning tree for the following graph(6 \[r'il'fxqm a.

b.

0xfT*TAfter delete r

0i[T'TTo find ffiD

b.

c.

8.

c.

Page 13: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

ir li illrfl

l'li ' r1*ilrh. Use Floyd's

(10 Markst

mg graph.

(6 Markst

(8 Marks)(6 Marksl

(6 Marks)With the first

(8 Marks)(6 Markst

Analysis and Design of AlgorithsSolutions for June-Juty 2009

PART A

La. Algorithm development process-Refer to Page No. 9-15, Figure No. 1.2.

b. Priority queue implementation as unsorted array-Refer to Page No. 26.

Priority queue can be implemented efficiently using heap data skucture.

Descending priority queue can be implemented using max heap. In a maxheap largest element (element with highest priority) can always be foundat index 1 of the array. Hence, the delete operation of the priority queue

requires deletion of the element at index 1.

For example, consider the heap

0r234

After delete operation, the heap looks like

0123456

c.

b.

To flnd GCD (60, 2$by applying Euclid's formula-Refer to Page 4-5.

Asymptotic notation used in algorithm analysis-Refer to Page No. 50-52.

For the given algorithm

i. algorithm checks if the given rnatrix is symmetric over the maindiagonal.

ii. basic operation is comparison

iii. the basic operation is executed (in the worst case)

c -.:I"-2Yn-t ILworssl Li=O L.i_i+t'

: Xt,, - t) - (i +.1) + 1l

t=(,

)-: 5 li-,o::.: ao(mt

-d-ri.B i

?;? -:ns$)i-€l Jf[.tilrfi

s' ;,fl-Br

:E: a-ifrlr;;r-qp ol l

Its-rd, ?{JlW

[-]s 3nl+ .lE

::a5eur g

e-; 3 s ]l*trf

a*: a".lr"s&

U ar'rbixulrr

r'.ri,o, oruplc€ r.+ilurq se]|:orruqp

l s/ar0Wdt8g:

Ftl lo uq

, 3rltlll,tllll,t

f1u-:caPp.; rrr**,F t'; t*)n-'::erph-- ru -,,

fro Srrurur

iear, ,olmbq",c4 eqf :t -,oqre

fo" o*""w

Fr XdlqutfeaU pefiar.'o "*be- a; mq

tur "oaw

frs a-.=au

Pc - wen

lr:,, sm

f==qw'l-*har-#

Htr-:

a.

2.

lm.gm.

ry--

10 9 8 5 6 7 3

9 6 8 5 J 7

-;a StEEs

Page 14: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

Q-14 Solved Quesfrbn papers

:(n-l)

I

: Ia-r-i)i=0

: Ii=Jr,-,r-I,=^"

Q-15 So/vedeues

_N_h{_M

when I::-l_I_,-[

M(n) -3e0

aJ.

a. Quick smr

euick satb. Algoriilmc. Exhausiw

+.

a. Inasetoflcomparisu

i. keynoii. sorer

The averagl

i. SmC-E

Ir-I'i=0 i=0

:(n- l)[(n-2)-0+

:(n-1)(n-l)-

M(n):M(n-l) +1+l+lto cumpute to multiply S(n_l)S(n-l) bynrn*n

M(l):0Solving the relation, we haveM(n):M(n-l)+3

= [M(n *2)1+Z+S: M(n - 2)+3+3: [M(n - 3)+3]+3+3

rr- [E:zler]

:(n-rtlrn-l;-(n-zl1L' 2.l

:(n- qlzn-z-n+21Lzl/l):(n-1) I\2)

_ n(n-l) . ,.,

- (n')

l": 1 n2e{n2)

iv. The efficiency class is quadratic.v. The algorithm can be further improved.

For the given recursive argorithm to compute the sum of first n cubes, thebasic operation is multiplication. Let M(n) be the number of times thebasic operation is executed. Then

ii. UnqC,E

forn> Ib. DFS algmirtc, Applicatimr

Presorting{cnumbers in abrute-forec at

5.

(n-2)(n-l)

Page 15: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

Q-14 Solved Quesfrbn papers

:(n-l)

I

: Ia-r-i)i=0

: Ii=Jr,-,r-I,=^"

Q-15 So/vedeues

_N_h{_M

when I::-l_I_,-[

M(n) -3e0

aJ.

a. Quick smr

euick satb. Algoriilmc. Exhausiw

+.

a. Inasetoflcomparisu

i. keynoii. sorer

The averagl

i. SmC-E

Ir-I'i=0 i=0

:(n- l)[(n-2)-0+

:(n-1)(n-l)-

M(n):M(n-l) +1+l+lto cumpute to multiply S(n_l)S(n-l) bynrn*n

M(l):0Solving the relation, we haveM(n):M(n-l)+3

= [M(n *2)1+Z+S: M(n - 2)+3+3: [M(n - 3)+3]+3+3

rr- [E:zler]

:(n-rtlrn-l;-(n-zl1L' 2.l

:(n- qlzn-z-n+21Lzl/l):(n-1) I\2)

_ n(n-l) . ,.,

- (n')

l": 1 n2e{n2)

iv. The efficiency class is quadratic.v. The algorithm can be further improved.

For the given recursive argorithm to compute the sum of first n cubes, thebasic operation is multiplication. Let M(n) be the number of times thebasic operation is executed. Then

ii. UnqC,E

forn> Ib. DFS algmirtc, Applicatimr

Presorting{cnumbers in abrute-forec at

5.

(n-2)(n-l)

Page 16: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

4.

Q-15 Solved Quesfron Papers Solved Question Papers Q-f 5

: M(n- 3)+3+3+3: M(n - 3)+3*3: M(n- i)+3*i

whenl:n-1: M(n{n-l))+3*(n-1): M(1)+3*(n-1):613*1n_l)

M(n) :3n-3e 0(n)

\Quick sort algorithm-Refer to Page No. 12+-125.Quick sort to sort 5, 3, 7,9,8,2, 4,7-Refer to Page No. 126, Figure 4.3.Algorithm to find the height of binary tree-Refer to page No. 133.Exhaustive search algorithm to solve TSP-Refer to Page No. 109.

In a set of l3 elements, the elements that require the largest number of keycomparison are

i. key not present in the listii. some cases of successful searches

The average number of key comparisons made by binary search ini. Successful searchk

Cu,,e (r) =logz (n- 1):logz(13 - 1):4-r-3

ii. Unsuccessful search

Co e (n) =logz (n + 1):logz(13 + 1):4

DFS algorithm-Refer to Page No. 157-158.Application of BFS-Refer to Page No. 159-160.

PART B

:)r !;Jtll; e1,: :ut "fft

ul si ll-c-!c: l, apolaP t

pegJoFJ a.ii

:lre Llns lo sLlol dli:.i,lt a

s ii-3o1tIeE ar:: Butr{t

lciLsrp oi PelaL",r, aUOP J

i'>s a.;: lautt 0' t :au3eu-.r 10 ,

, _ = < .,-r4{

3u: a-i:dE, (y, a.roiuqrel

''lsorouti:'a}dxa qlurtrr s

'' 1=nolr.rqrgrelfsllE a

d!;ls 4;sAt ls uo!$

Ebes.

imesthethe

b.

c.

b.

c.

'3- :l;uiql

B i-"a,f i.lepP:suor*fi8,,.E,}:':!a+u

. };r1 ' :-re rorrsf--," ,*oiro 3r..:.r'r-Llp6

iea, ,: ranop a"c, aug, 1

r rr lr> -.,: ::a1q)6r pa=q saI

Fi Ydl slrqJ-'

heru pretr al

l8,.*o ** s

* P tut *qPDia: eLi IlgSIps 1--1ua,th= - z1q.| ,-.-, srrq*iIe;aspefrfri

lffiu'ktgi

i rlm, !fr.4il

>l

5.

a. Presorting-based algorithmnumbers in an array of 'n'brute-foree algorithm

to find the distance between the 2-closestnumbers and its efficiency comparison with

tfe 3;E

Page 17: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

Q-16 Solved Question PaPers

ALGORITHM Present Minimum Distance (A[0' "'n-1])//Solves the problem of finding minimum distance

//between the 2 closest elements

//Input: An arrayA[0...-n-1] of orderable elements

/iOutput: Returns the minimum distance

Sort the arraYMindist:At1l -At0lfori€2ton-1

if ( lAiil - Aii - 1l l)mindist : lAtil - Ati - 1l I

return mi-ndistworst cast efficiencY is

T(n)-T.on(n)+T..-(n)e O(nlog n) + 0(n)e O(nlog n)

The efficiency ofbrute-force algorithm is g(n2)'

This is because there will u" o("= l) 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.

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

To construct open hash table for the input 30, 20, 56, 76, 31, 19

Assumption: Let the hastr function be

h(k): (sum of digits of k)mod l0h(30):(3+0) mod lO: 3

b.

c.

h(20)ah(5q ah(75)ah(31)lh(le)i

lKqlo*,

0

[T19:

The loc

Key m

DynnFord275-

Soh*io

Kru&Li$rL

lE6lw"tr4

lr"t-rllr*,*r

6.

Page 18: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

{)tI

h(20) =(2+0) mod l0:2h(s6):(s+6) mod 10: 1

h(75):(7+5) mod 10:2h(31):(3+1) mod 10:4h(19):(1+9) mod 10:0

20

T75

The load factor = A: nlm

31305619

fficientDe-

Refer to

tErt x

2

0.6

2

7.

b.

U.

a.

Total number of keYs

Total number of cells

: 6 :0.6: 60%10

Key comparisons in successful searches is

s=1+

:1*

: 1.03

Dynamic programming explanations-Refer to Page No' 265-266'

Formula for Floyd's ulp'o'"tt to flnd shortest path-Refer to Page No'

275.

Solution for the given graph-Refer to Page No' 276'Frgttte 8'7 '

Kruskal,salgorithmtofindthecostforthegivengraph.List the edges in a sorted order'

Edges ab bc ef af ce be cd de cf bf

Weieht 6 7 7 8 9 10 11 t3 l4 20

Invertion statusx x x x

lnversion order I z -') 4 5

f;fB 3,n I is

So/ved Question PaPers Q-17

J

l[rI

l#

::: apoFPla3;C]a, ar€

B€ -l1S io-.!Ol Jllii\\

e! au:3uc1rsrP c"i Pa!3u\t ?f,GD /(

!:'is ai; -a'roii , t:aLBE;L +o E

L;3-:l3sl o

A an!'iiL.Fli-/:5c'oLiula]

lxa qriil'n sa'

.5.$aDiliqfal'Sr?)l)PlfP fl'-

dr.i15:1')iA Io rlollE

: ;- ;ri,qr,:

I i!.c+ JeSOr

fc:soa,u ffi<

, i -::: ,aun'

P"''=e qcms

i^--s :a iYe

io :, 'rurPr

F"u "a ra'op:=rc. af, I

n [) _..lf,aHp" c*sec sa

[t>c: suut

Pa2 PueS Ip.L*l -u 'Pa'"+@F.* L€: a!:ile4I

fs:- +.ue

fc: e+W

lu-:.l roulle =a-w *

ii' '*dp b*J

itmi ,rrsn

Page 19: Solved Question Papers -  · PDF fileAnswer any FIVE full questions, ... Explain important fundamental problem types of different categories. ... Q-2 Solved Question papers

Q.18 So/ved Quesfbn papers

8.

Total cost:39Huffinan tree conskuction algorithm-Refer to page No. 31r-312.

l;:*t* tree for 3-elements invertion sort-Referto page No. 369, Figure

Difference between back hacking and branch-and-bound argorithm.

statespace tree to generate first solution to 4-queen problem*Refer toPage No. 396,Figtxe 12.2.Observe that, the solution is

Another solution is its minor image

USN

I-fIl-06cs63

Fourth S200y

Time: 3 hrsNote: 1. Ansm

b.

c.

a.

a. Explain {chart.

b. Define &ri. Specirii. pathe

a

iii. Setsuc. Write an a

numbers"

a. Prove ther

If t1(n)eg1(

then t1(r

b. Write an alalgorithm!

c. Explain 6cIimits. Cq

a. Discuss horDraw the tro

b. What is sffic. Write th" aI*

(l) Non-optimization problems(2) Employs depth first search

traversal

(3) Requires a stack or userecursion

(l) Optimization problems(2) Employs best first search (not breath first

search) traversal(3) We can use a heap to find the best node (the

node with the best solution seen so far)

aa

aa

aa

aa

c. P and NP problem*Refer to page No. 373_374.