# ALGORITHMS-2

Graphs- traversal, connected components, shortest paths, spanning trees; omple!it" classes #\$ onsider a graph G % &', () and sets '* and (* +hich are s,-sets o. ' and respectivel"\$ G* % &'*, (*)\$ /hich o. the .ollo+ing statements is tr,e0 &a) G* is a s,-graph o. G &-) G* represents a graph &c) G* is not a s,-graph o. G &d) 1one o. the a-ove

2\$ Let G % &', () -e an ,ndirected graph +ith a s,-graph G# % &'#, (#)\$ /eights are assigned to edges o. G as .ollo+s +&e) % 2 i. e ∈ (#, # other+ise A single-so,rce shortest path algorithm is e!ec,ted on the +eighted graph &', (, +) +ith an ar-itrar" verte! v# o. '# as the so,rce\$ /hich o. the .ollo+ing can al+a"s -e in.erred .rom the path costs comp,ted3 &a) The n,m-er o. edges in the shortest paths .rom v# to all vertices o. G &-) G# is connected &c) '# .orms a cli4,e in G &d) G# is a tree 5\$ onsider a +eighted complete graph G on the verte! set 6v#, v2, 7 , vn8 s,ch that the +eight o. the edge &vi, v9) is 2:i ; 9:\$ The +eight o. a minim,m spanning tree o. G is0 &a) n ; # &-) 2n ; 2 &c) n 2 &d) n2

<\$ To implement =9i>stra*s shortest path algorithm on ,n+eighted graphs so that it r,ns in linear time, data str,ct,re to -e ,sed is0 &a) ?,e,e &a) Stac> &c) Heap &d) @-Tree A\$ onsider the directed graph sho+n in the .ig,re -elo+\$ There are m,ltiple shortest paths -et+een vertices Sand T\$ /hich one +ill -e reported -" =i9>stra* s shortest path algorithm3 Ass,me that, in an" iteration, the shortest path to a verte! v is ,pdated onl" +hen a strictl" shorter path to v is discovered\$0

&a) S=T

&-) S@=T

&c) SA =T

&d) SA (T

B\$ Let T -e a depth .irst search tree in an ,ndirected graph G\$ 'ertices , and v are leaves o. this tree T\$ The degrees o. -oth , and v in G are at least 2\$ /hich one o. the .ollo+ing statements is tr,e3 &a) There m,st e!ist a verte! + ad9acent to -oth , and v in G &-) There m,st e!ist a verte! + +hose removal disconnects , and v in G &c) There m,st -e e!ist a c"cle in G containing , and v &d) There m,st e!ist a c"cle in G containing , and all its neigh-o,rs in G

s.<).B). &C.m Spanning Tree &MST) o. 9: M 2\$ (ach edge &vi. +e do a -inar" search on the path . and onl" i. it stars at verte! #3 &a) &#.ormed -" adding e to T.ollo+ing statements is TRI(3 &a) T* % T +ith total +eight t* % t2 &-) T* % T +ith total +eight t* J t2 2 &c) T* K T -. An) &-) n2 . +eight +\$ /hich o.m spanning tree F\$ onsider the .rom the lea. e is not in a minim. the a-ove D\$ Let + -e the minim.ind the correct location . &5. the a-ove ##\$ An .<).B). &#. edges in G\$ Let T and T* -e the minim. ## &d) 2n N # #2\$ Let PA -e a pro-lem that -elongs to the class 1G\$ Then +hich one o. are selected -" GrimHs algorithm i. &#.m spanning tree has an edge o. &2.or a heap.aring the +eights o. and in +hich order. &5.m spanning tree containing e\$ &-) I. &5.5).C).A).B).C). &5. v9) is assigned a +eight i N 9\$ A sample graph +ith n % < is sho+n -elo+\$ /hat +ill -e the cost o. &2. &#.A) &c) &#. v2 7 .or PA .ic edge o. &#. then in the c"cle . vn\$ T+o nodes v#. &5. &5.B). n N # &c) Bn . &5. +eight + &d) e is present in ever" minim. the .<).cted -" s4.5).ollo+ing is TRI(3 &a) There is no pol"nomial time algorithm .m spanning tree T.ndirected graph G&'.m spanning trees o.C).C).ch a -inar" search is not possi-le &-) omple!it" is O&log log n) &c) omple!it" remains O&log n) &d) 1one o. the .ollo+ing graph\$ /hich edges.C\$ In the I1S(RT operation . +ith total +eights t and t*\$ /hich o. the Minim.<) &d) &#.t total +eight t* % t &d) 1one o. to root to . &5.A) #2\$ Let G -e a +eighted graph +ith edge +eights greater than one and G* -e the graph constr.5).m +eight among all edge +eights in an .C).or insertion\$ Then the comple!it" o. &5. &C.5). () contains n &n L 2) nodes named v#.C).C).ollo+ing is EALS(3 &a) There is a minim. &2.ch a graph +ith n nodes3 &a) &#O#2) &##n2 . 2 J :i . the I1S(RT operation is0 &a) S. &5.ndirected connected graph\$ Let e -e a speci. the .C). all edges have the same +eight &c) (ver" minim. v9 are connected i.A) &-) &#. &2. G and G* respectivel".

&-) I. ? is 1G-hard &-) 1one o.n2 ) &c) S&n log.ollo+ing algorithm\$ Algorithm @&G. ? is 1G-complete &-) ? is 1G-complete i..ltiplications in the . &n))3 &a) .n) . . additions and m.&n) % #.L #\$ Then log. &n). g&n) % #2 log n & ) . v) % tr.or 90% # to i s 0% s N 9Qi ne!t 9 ne!t i s 0% sN#2 &a) n &-) n2 &c) n2 N 2n &d) n&n N #) &e) &n N #)2 #C\$ Let .nctions .n) &e) S&n log.&n) % n5.alse other+ise\$ &e) It ret.rns tr.&n) % n5. G\$ Mar> .rns .&nR)) &-) S&log.) Inp.&&n2)R) is &a) S&log.rn .n-mar>ed and all edges are .alse other+ise\$ &d) It ret.ndecida-le #5\$ onsider the .e i.rns . Eor each edge &. then it is 1G-complete &d) PA ma" -e .&n) % n2. g&n) % #2n log n &() .ollo+ing is tr. @&G..nctions are s. v) is not la-elled then 6 i.&2 nR)) 2 &d) S&n log. none o. &n) is O&g&n)) and g&n) is not O&.ollo+ing code3 s 0% 2 .. . the . v) as discover" i.t0 Indirected graph G.rns tr. G is connected and it ret.alse /hat does the algorithm do3 &a) It ret.ci-le to pro-lem ?\$ Then +hich o. G are .or i 0% # to n s0% s N i .rns .e then ret. () -e an . and verte! . o.rns tr.e &a) G is 1G-complete i. has at least one edge la-elled discover" and it ret. &. G has at least one c"cle and it ret. an" verte! v is mar>ed and it ret. g&n) % n5 N n #<\$ Gro-lem G is red. g&n) % n2 log&n2) &-) .ndirected graph\$ Initiall" all vertices o. PA can -e solved deterministicall" in pol"nomial time. g&n)\$ Eor +hich pair the .. . PA is 1G-hard. the a-ove #A\$ Let G % &'.e 8 else ret.alse other+ise\$ #B\$ /hat is the total n.rn tr.alse other+ise\$ &-) It ret. the edges incident on . v) incident on .. do 6 i. is la-elled as discover" and it ret.ch that . then G % 1G &c) I.e i.e i.rns tr.m-er o.rns . G is 1G-complete &c) G is 1G-hard i.rns tr.e i.n-la-elled\$ onsider the . &n) % log n.rns . g&n) % log n &=) .ollo+ing pairs o.rn tr.e 8 8 ret.e i.alse other+ise\$ &c) It ret. v is not mar>ed then 6 La-el &.