0% found this document useful (0 votes)
172 views128 pages

Design and Analysis of Algorithm

Uploaded by

Kushal Nagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
172 views128 pages

Design and Analysis of Algorithm

Uploaded by

Kushal Nagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
e@2 QUANTUM Series Design and Analysis of Algorithms www.askbooks.net A.S.IK. Always.Seek.Knowledge All AKTU QUANTUMS are available * An initiative to provide free ebooks to students. * Hub of educational books. Ul CR UCC em COE} eC ae Cen er incom marcus 2. We don't intend to infringe any copyrighted material. Pa ura cr ek uit DCR Ar ee CROC RLS Loe PWN hina nes i ee PUBLISHED BY: ApramSingh Quantum Publication: (Unit of Quantum Page Prt. Lid) Plot No, 5827, Site 4, Industral Arca, —<=<=<==C ONTENTS === Sahibbod, Ghazishnd-201 010, . ‘Phone: 0120-4160579 ROS-502, Email: pagequantun(@gmallcom —Webite: www.quantumpage.ain | Delhi ie : U650, East Rahtas Naga, Shabdara, Delhi-110092 ‘UNtra:iwTRODUCTION (0-48 01-998) ‘erie: Alyn Agri Coney of Neti. (rand An ot Algorithm © AUR Resmi Shih ae Ques So Mere Sr Hsp at Campa No pt of hie pba may be epoca tne fl soing Ago Song ier Tae ‘nay fom by any mons! poison UNIT: ADVANCED DATA STRUCTURE. 2-1B.02-485) Tufte conned i thre derve rm sources eS hh Ts B= Tes, anil Hep, Por ep Ts baler ote lable Every eferthas teen made ensure Se accurecy, however rier the publisher nor he authors UNIT GRAPH ALGORITHMS. 1803-408) susrance he accuracy completes fay formation published here and either th publisher othe shoes shal be espnshie fr ny eros emis, or damages sing out of wa of inrmaton Divide and Conquer with Examples Such a Sorting, Mai ‘Muliplcaton, Cowes Ha and Searching Greedy Methode with Examples Such ts Optimal Reliability ‘lication, Knapeac,Minunum Spanning Tes = Pn’ and ‘ruta Agontins Sigle Source Shot Pats» Di’ 2rd Balnan eed Algo Design and Analysis of Algorithm (CSAT : Sem-5) . LUntr4 : DYNAMIC PROGRAMMING (18104-408) 1 Balin : 21041 Dynamic Progaming with Exemples Such as Koapeset Al 2 Bain : 20112 Rare fat - Wah and Po Anti Romane 3 Baiton : 2072-13 ‘Moan Pie ected an ound with Exp Sah aveing 4 ition + 2079.24 Scien Pblem, Grph Cong n Ques Pedi Hanlon 88 Baition «201615, jen tnd Som 0 bes 8° Baition : 2015.16 et ee UstEs SELECTED ToPICs 1B.05,34m) ‘ ‘Algae Computation, Fst owe Taf Sing Mating 8% Baiton : 2017-18 ‘Theory of NP-Complwnesa,Approsination Algona 98 Bdition : 2018-19 (Phoroughly Revised Ealition) 4 Randomized Algor” 10° Eaton : 2010.20 ‘Shorr quesrions (sqb1080208) Price: Rs. 120/- only SOLVED PAPERS 2013-1470 2018.19) (sP1Btesra2e) ‘Printed at: Mayank Erp De TOO: Introduction (1-28 to 1-148) A. Concept Outline Por D nnrne 1B B. Lang and Medium Answer Type Questions vovncwnn BB (1-148 to 1-808) Comparison of Sorting Algorithns Sorting in Lingor Tie A. Concept Outline Par 2 nvr LAB 2B. Long ond Medium Ansier Type Questions seven -15B LAB (CoHTSem-5) | tactin Algor Arateg Rina Copley of | Algorithns, Growth of Punetons, Performance Measurements. CONCEPT OUTLINE : PART-1 Agri An algorithm sa sequence of computational teps ‘at easfor the input ine the outpes Input» [Algo + Output + Complexity of algorithm + Complesity ofan algorithm is Aenea ty two tera 1 Timecomplxty & Specemmpeity + Analysis of algorithm The analysis an algorithm provides ‘me bs inferatin abst that grin ke time pace, erormance oe 1 Analorthmis ast orale for crrying ut alelation ether by hand ‘roa machine, 2. Ieisa ine diepy-atep procedure toschiev required rsul 8. Itisasequence ofcomputationa steps that trasformtbeinputint the tp 44 Analgrthm sa sequence of operation performed on data that hae to ‘organised in datastracturee ‘Characteristics of algorithm are + 1 Input and output: These characters equire tht an algrithen ‘rods oon or mors oupats and have sero or ore inputs that are ‘teraly sapped. Design and Analysis of Algoihne AMLCSIT-Sem.6) 2 Detinitences + Each operation must be perfectly clear on ‘ambiguous. | Bsfectiveness: This requires ha each operation shouldbe fective, {vend tepcan be done ly aperson sing panel and paper inate sount ef tine 44 Termination : This charstvieti equres that an algorithm must terminate after ite momber af operations. ‘Gaeta ] What do you mean by analysis or complexity ofa algorithm ? Give its types and cates Tarwer Analysiomplesity of an algorithm + ‘Tee complet ofan algorithm i function gn) tat gives the upper ‘ound ofthe sume af operation Cr Tuning tie) performed By an slgorithn when the input ane ‘Type ofcomplesity: 1. Space compleity:The pacecomplesty ofan algorithms the amount ef memory ened trun to completion. 2 Timecomplesity:The tine complet fan algorithms the amount ‘dine teed toruntoconpltcn, Cases ofcomplesity: 1 Worst case complexity: The runing tine or any given ise apt wllbelowes than the uper bound expt possibly for some values of ‘etepat where the marimum i teched, Average case compleity‘The running tie foray given sie inpot rib the average suse f operations over al problem instances Gragrenaie. Beat ease compleity The best case complesity of the sort ie the faction dened by the minimum numberof tps len on 80 [nstane of ‘QueTS.] What do you understand by asymptotic notations ? Describe important types of arymptotic notations. Discuss aeymptotie notations in bret. [RRFUSOTETS MGS] 1. Aymptte notation ia shorthand way to represent stat possible ‘d'soest pase’ running time fran a ewe leorith, ing high and introuction 14m (CHT Sent) —— ae a aot n wt tin 8 Tre umadtofind complete af functions. setts nd spl om iphoto aan er oe tina tintin ei tant 24 Terao thr i vie etn 28 8 Madani afte vn fn vase temo Clg and et ils and ess) 0) se) saitowa) ig. 135. 2 Notation Upper bound): ‘2 Big-h ie formed method f expressing the upper bound of an ort ranaingtine- 1h This the measure ofthe longest ameunt of time it could possibly {efor the algorithm te complete More formally fr non-negative fenton, (and gn) i there (Sean intger ng aad sonotant¢> Ouch that fr allintepers fo sea) A Then, f(a big oh of). Thine denoted as: Tie Out) the at of fanctions which, asm gets large row fster than constant the fi * fin)= Oe ign.) Design and Analysis of Algorithns LED(CSITSem.5) & Notation Lower bound ‘8 Thisnoaton gives alower bound fora function within a constany factor |b Weverite in)» tn) ther are postive costantsnande sch ‘ht tothe ightofn the vloe off) aleayslies on above ce) a) cn) *ay=m.4) (ners) |. Little motation () tis used to denote an upper bound tht i ‘sympa ight because upper bound provided by O-nottin is ott. ain) = tn) foray postive constante> 0, aconstantn,>Osuck that 0s fim 0,fconstast iO such tO caste) Lar contents the number fsb problems in the recursion ‘Ub he portion ofthe orig problem epresonted by each subprotens fy Tan pen etre Ej ‘he ene ltt fen tue eet poet teb0 te i: Twists amie: Tweet) +08 the given formula the variables ot he allowing vas Sines this equation ds, the first case ofthe masters theorem appli tho| sven eerrence relate, tus reeling soation Tu) =O) = ei) case2: Irie tre that: fin) =@tnhn) eftows tat Tin) = tm ae (gin) rw ut2) +n Inthe ig he ig ae = 2b 2,fln)=1, loge =log=1 Brent a rouction 1-9 (cat Som : maeanaen 7 Sint patent tod cae he ase tere ai ‘Relive curene relatos, thas esuting sl —c Thay in og tn log fir) = nse“) for B> 0 ndifit letra itor (2) se ora anal rata eee iat Bw =a) ot rwait(S)o0 ve genieseshvaea get te tag ate 7 oa, b= 2 fin) =n, loge = log, 2= 1 ee xno) ) fi) = 24n!*1) = 0008 Since th equation tlds thir nse of Master hoorem is apiied Now, we have te check for the second condition of third ease, fi roe that 0, fllows that: Tn) 017) we inert once more the necesay value, we gt Tw) cow) Thuy th given reeuene lates Tn wasn (0. BE] Te recurrence in)= 7a) +n* describe the running {me of an algorithm A. A competing algorithm A has a running. time P(n)= a (nd) ni What isthe largest integer value for nie erm tater han? nw 77(2) +08 an Tide or (ent 213 Here, equation (17.1 dines the runsing tine for algorithm A and equating, (17.3) defies the running tine fr algorithm A. Then for finding vale of forvwhich A's seympteial faster thanA we find asymptotic tation or ‘the rearrene ty ting Masters method. [Now, compare eustion (171) by Ni 1{4) 0,thennl=n. (nD! Here thea cti or arbitraryn idee in terms soley ‘allen whichis er tthe base value. ‘Observe that thisdeiton ofa irecursive, since itrefersto itself when, swe =D {Wee Whats recursion tee? Deseribe, newer 1L Recursion tre it pstoral epresntation of an iteration method, ‘phshisinthe frm ofatres, whereat each level nedesare expanded 2 erecuson teach ode representsthe cst of single ubproblen. ‘8 Recursion trees ar partialarywsful when theecarrence describes the rmning tie of did and conquer aorta. 4 Arcuri tee ie est edt generat a god guess, which is then ‘eiGedby the substitution method. |& leeemuthd tosaloe the complet of algorithm by dingramming thereurie neti cali. ‘This method canbe eee oe Solve the recurrence: Tind=Tn-1)+Tin-2) +1, when TO) = 0 and Tay=1. aver Tin) =Te-0) + Tn-2) 01 ArH esl, TU) willing to wea ache bene FP ete sPeteae es : a ae oN Ly aoe [ssmern terme oti reese -e-l-12009 Solve the following recurrences: Tin) = Tin) + Teal) + Ti) +m a Ne / aceite) yaa) taite) 2 ANAK ANNAN INININ tag ines cor = a(rloga [QGETTE Consider the recurrences Tia) «30 (aa) sen, Tin) = SF (ni) +n where ¢ is constant and n isthe number of Inpots, Find the atymptotie bounds. Design and Analysis of Alorthans wer] tm) = 302) een vrecan dren eae te fr 21 Ta)=nenent on Ta) = AUeogm) logy ties oa ™ = 7S No nN JNINININININININ Tin) «nen n ont logg times | Ta) =0inlg) y Tw) = 6r(2) +0 sy Comin ein tothe (2), ee | ok fn) =nt Spl end = 9360 ) ‘Now aply case of Master theorem: find ® cx) ayers = Aint 884) = ofa) whore B= Gor Hience caso of Masta’ theorem eatin Tin) =f) Tin) = nt) REETIE] sotve the fotowing by recursion tree method i Tin) = n+ To) Tenis) Es —————__ Introduction | utng end Order Sttne: Sha Sr, Quick Sor, "Merge Sort, Heop Sort, Comparison of Sorting i © Salgorichn, Sorting in Linear Time. CONCEPT OUTLINE : PART-2 ‘+ Shell Sort: Ttis a gorithm that roughly sort the data fst tnd move large elements twards one end end smaller ones toward the ober Complesity: Oe) ‘+ Heap Sort «The heap isan array that can be viewed a8 & complete inary tre. The tre filled on ll lve except te Towest Complesity O(n og m) + Merge Sort: Iworks on divide and conquer approach Set it Aividesaistinta wo sublis and sort and ten combine ae 8 ow sorted ne list Complonty:Olnloen) * Quick Sort: I mors en the principle ofdivde and conquer. It ‘orks by partioning sven eras. Conleity: Oi) (Questions Answers [ioe Aner yp ened Anever Type Qestions N ‘Que TE. ] Explain shet sort with example: Aaswer | 1. Sheleortisabighy ficient sorting api ands bated onnserin sort algoriti nd wecancoe Fess. 2 rough sorts the data fist, moving args lees vars one ng ‘ed sal elements towards the te. 4. Tnshelsort several pases ove the datas performed, at iae thay hola ‘Aer hel pay, the data ify etd .Thesel srt dor ot rt the dats iteel, tineresss the effin of othersurting sgt. Algorithm: Input: Anaraycflogth n with ara ements numbered Oto ~1, Lee round) 2 hie ine>0 2 Briwincton-1 temp al “leis ine > temp aio te jejnine oneuap 4. Sane round 22) Forezample: 5] 86] 75] 20] 05] 90] 60] 65] 90] 50] 10] 75] 65 ‘Thedistancs between the clement te amped is 8. The ub generated vvith the ditane of ara fallow: Subsler al) al) alo) al) allt) Subéle2 alt] ala) al] ato} Subfles a} al6)— lB) alld) Toputto pas 1 with stance «3 (LD | [oo Tes Too To oe [es T I T rf @ (Output of pas isinput to pass 2 and tance «2 1-108 (COT-em-6) troduction w]e] 90] «50m [oa] v6 [75 [| 65 [oo [05 COvtpotof pas 2is input to pass and distance = 1 fj sno ea saa ase Sts et w {FOC EEE: Las] r5] 90785] oy Outpetofpass3 mallee foriejsiton AU Oand Ali) > key dealt eld feta AA Chey Design and Analysiof Algorithms ATI CSTS em QueTAT | Write non-deterministc algorithm fr sortinis ae | ‘Non-detersstialgpritums are sgerit that, ven fr the same inp ‘eves diferent ehaviours on diflerent rune, erations and executing, ‘ea «Othe atare Bi = At) endo fife 1ton—1d0 ify <1) een fatore sealer ran) 1, roe ‘Que AE | Bopain che concepts of quick sort method and analy =_—_——— 1-180 (CSITSem-) Introduction & doirauiss 6 tenietel : then exchange Al) © AUT 1 exchange All Here return +1 ‘Example : This exanple shows that how “Piva” and "Quick sort” work apps eas 8, 9.2.6 5.3.5.8, 9) Sor the array A sing quik sort algorithm, Solution; Given array tobe sorted step Thea Peed ob si lees, Pet P= EEE ell P ‘Step 2 Find first element larger then Poot (ake underline) and find ‘State oo lage han pivot rom end makeover ln. es Atscomplesity with watable example. [ARTOOTEI Maris] Tarver Quick sort: (ui sort works by prttining a given array Alp «nto two nonempty ‘barry Alp -g~ land fg 2-n7] euch tat every key inAlp gil Tnsthano gil to every ky ing +1 Then the two subarays are Derted by ecrcrecall gue oor, Quek Soet Apr) A lperthen 2 qe-Partion(A,p.7) 3 Recursive call ta Quick Sort Ap. @=1) 4 Recursive clo Quik Sart Aq 1,7) Asafirt ste, Quick ort hace ae pvton thet inthe arry tobe ‘arte, Thon aay ie partitioned on ether ideo the pvt. Bement ht sles than or exalt pivot wlmove tard the lft lerments that seater than eas tie wl move toward the ight Partition A,p,) Lb seabl 2 top 3. forjeptor-1 P 3 + —— ont oc ove ‘The pootershave crosed “averting on lft underlined 1-208 (CSTT-Sem-) Introduction DEER: P Now, voting process omplete. ‘Step 4 :Reeursivly sort ubarrays on each side of Pivot, Subarray 1: [271 ]3]1] Subarray 2: [9]5 [6 [5 [7 [5[8]9] Fist apply Quik ort foreubaray 1 Bes Usdelne ? Underline ‘The poinershave crossed, ‘ce, ovelne nef underied. Sea pvt wth overine ‘Now, forsubarray2we spp i = on EDL P + a HELE ‘The pointer has rosea, Then swap Prot Leelee Scbaray 3 Bs Tel] «51 i Fi touah P ‘Swap ovrline with Pivot, (ele Oreline on ef of unerined ‘Sap Poot wth overlie, ‘Now combine alee sobarrays «EE |e Sorted array I Piet ‘Analysis of complesity Worst case: et Tn) be the mort at time fr quick orton inp sien We have Ta) = max, Tg) + Ta-g=19 #(n) L382 here qranges fom Oton~1,sine the partion praduces two eas, tech ving ste n= 1 Now we assume that Tn) 0 aloo se an pick‘ and’ large enough 20 that m log m+ b> TU). Then for nS i wekave Tn) 2**0,,.2nlohlogh+)+ 009) = Bah, blog h~ WBC) + 2 (-De0n . 18) Atthis point we are ain hat, 0, Hogs 12 lg n U8t0) ‘Substituting this claim inthe equation (1.18.4), we get Ta ae Ue ogn i 2 bin—1) tn) Sanlogn-anlts 2 in) 183) 1st 18, 9) ad al tis and ween choos large enough so that al dominates tn) 8, ‘Weeoncludo that QUICKSORTs average runing time i 6 og n). [RERTIOT] Discuss the best cate and worst case complesities of guk sort algorithm in deta, Inteodution 1-221 (C8ITSem-0) 1 The Bet thing that cold happen in quick srt woud be that each pattoning stage divides the srayextyin hale. 2. mother word, tho best tobe a median ofthe kee in Alp. every time procedure Partition sealed, {8 Theprocedure Partito’ always split the array tobe sorted int two cequalsted array 4 Ite procedure Parton predces two regions of sien then the recurrence relation Tia) s Ti) + T+ tn) < 27) + tn) ‘And rom case (2) of master theorem Tin)» nlogm Worst case ReferQ.118, Page 1-17B, Unit ‘GeeTBO,] expan the concept of merge sort with example. "Merge sorts asorting algorithm that usesthe des of divide and conquer. ‘hislgrithm divide the rrayint two halves, ot them soparately snd then merge them. 8 Tis procedures recursive, with the base eiteria hat the numberof ements ia the array tnt ore ha MERGE-SORT A, 9,0) MERGE-SORT Ag +1;2) MERGE 2.4.7) eee pe tere : : : 2 (Createarape RiLongel fori=ttom, y+tlana & Lineapsi-a er Design and Analysis of Algorithms endfor 5. forj=ttony mn RUl=Algea or Hin + l= Rng ae uasRy AU) reeey ele AW=RU fair endfor & et Example: 10, 25,16, 5,35, 48,8 1 Diente aes 2 Considerthefirstpart:10, 25, 16, 5 againdivdeinto wom says Ws wg a} Bx} ‘% Consider the second half: 95, 45, 6 again divide into to subarraye 8 6 Ba 5 esa] 4 Merge these tra sorted sub-area, a4 C9 Som "Thisithesorted array. ‘Gee ] Determine the best case time complexity of merge sort algorithm. =a 4 Thebes ease of merge srt oesurs when the largest lement of ne xray is smaler than any element inthe othe ary. 2 Forthiscaeonly 2 comparisons of array elesnents are made 8 Mg sort comarons are band hy the rearens eto of ‘therecursive calls used in mer 4 Asia the ry inte aoe een eon eed Iotrodstion rove r(S)e1(2)s0-27(—)+2 stn 5 By sing arable # to lndleste depth of the recursion, reget r= 0(8) oan lane Forth bust case there arealyn/2comparisns hence equation (121.2) canbe wsten at ro xa(s)oah 1. Athott level oes tse Ben ‘tone 4 Sotherecurec faction df Twa e7( 52) Bogan same 5 Bm) =O ec heb en cope meat tno ‘ReeTB] eoplainnoup srt algorithm with its analysis oR Sennen Design and Analysis ot gorithms ‘Whatis the running is already sorted in T-25B (CST Sm, time ot heap sort on an aay A of length nth increasing order ? " ‘on Discuss the complesity of Max-hespify and Build Max tte, one al Peeters naiue aus the second angst items found and this proces isrepested for allots clements 2 The general approach afheap cote a fellows ‘From thegivenarray, bud the inal max heap, ‘Interchange theroot (maximum) clement withthe ast element, ‘© Use repetitive downward operation fom rect node to rebuild ho ‘heap ofsie one las than the starting 4 Repeat stepa and util there ae no more eessents, Analysis of heap sort: ‘Complexity ofheap sor forall cassis Otn logy). ‘MAK HEAPIFY 4,0): eight itt seap-sie (A) and AUT > Al) then ingest 1 ls largest = \trshesp-ice [A and Al >A largest hen anger ‘flag’ ‘then exchange Al] ¢ANargest 10. MAKHEAPIFY largest pena nee 2 fori etength A dom to | 8 doexchange Alt «A “ heapsize Al «heapsige A]—1 5 MAKHEAPIFY 1,2) ‘BUILD.MAX-HEAP (4) 1. heapsize CA) «length Ad 2 fori «length (1/2) downto 1 do 1-208 (C9IT-Sem-5) Introduction 3 MAK HeapllyA,0) ‘Wecan build a heap fom a wnorderd ary in ner tine, ‘The HEAPSORT procedure takes time O(n log) since the call to [BUILD _HEAP aks tie fn) and eath of the = Las to MAX Heap takes tine Og. ‘TeAaR] Sort the following array using heap sort techniques + 15, 13,2,26, 7,17, 20,84). Discuss its wort cate and average case ‘ime complexities. (ARTO BOIE-Te, Manis 0] ‘anewer Given aay: (5, 13,225, 7,1, 20,8, 6 First we eal Bald a be heapriee Al = 9 P 124403, ell MAX HEAPIFY (A, {eine call MAX HEAPIFY (i) ‘All BA = 25,Alel=4 Ausain ausavi ‘Now ell MAX HEAPIFY (4, 3) ‘a3, at Amat larpes= 6 ‘Aid > A larset) 20317 largest = 7 7, =20 rgest Ah eA argest AU> AU AMsatl ‘Now ell MAX HAPIFY 1.2) All AU =, dangest= Adare] > Ab) 1 laget 20 6-8 Margest) Now, ausain AaDAb) Wo call MAX HEAPIFY 2) AWeaw sets Atanget > A] and args 2 ‘AUle> A Mares) larpot=2, 90/2 Design and Analysis af Algorithms 1-27B (CSITSem.5) asm osttsem Inadton 1B a _ |g Om Gg fh 00 © goo CaERRT TR lil , get sina AX HEAPEEY A, wept Alle A Dargest) Now, All A 7] St largest i, (largest «Afi OGIO RC) So foal ree after Bild MAX HEAPLFY exchange A [1] and AIT and size Q x 2Te[s[s[7 [in| 9 06 B Asin call MAX HEAPIFY (A, 0, we gat 17-126 Now f= 9 downto excha MAK HEAPIFY U, iene ‘exchanging A (116-4 (9) exchange (1) and AI6 and now - = Terps] : ‘Again call MAX HEAPIFY 4,1), (eset Tapes] ® ae tiga ana eect LOso ® Grrr. | ee * Ari ell MAX HEAPIFY (2) “Mm EE Design and Analysisof Algorithms 1-291(CST Sy, ‘exchange A {1} and [4 and © fY ‘all MAX HEAPIFY (4,1) exchange A (0 and (3, size = 3-162 re cries at tase oo 2T+[s[7[*|s["] =] ‘Thus, sorted array: Average case nd worn ease compeaty ‘Wehave sen that the running tine of BUILD-HEAP bs fn. The hespsort algorithm makes acl BUILD-HEAP for eeating 2 man hap which wil ake Oy tine and each ofthe r= elo MAX-HEAPIFY 1x up the new heap (wich fs ecaed fer exchanging theron ny dsreatng oe es 4 Welnow MAKHEAPIFY takes tine Og) ‘hath total unig te for the heap sr is On og. Inteedeion 1-201 CHIT Sen) GueTAE] Wht in heap sort 7 Apply heap sort algorithm for sorting 12344, 5,0,7,8%9, 10.Also deduce time complexity of heap rt Taswer Heap nor : fer Q.L22, Page 1-26, Unit Numeral Since the given problem isresy in nad frm, So, teres eed to aply any procedae on given problem. Gueiae [explain HEAP SORT on the array. Ilustrate the “poration HEAP SORT onthe arrayA=(6,14, 325,210,207), (ARTO 2017-8, Marks 1) [ewer Heap sort: Refer Q 1.2, Page 1-248, Unit Numerical ‘Originally the given aray (6, 143,25, 2, 10,2, 7,6 Firt ne all Bud Max heap Despite Al =9 f= 4 call MAX HEAPIFY GA, ) est we cll MAX HEAPIFY(, §) ‘AU)=7,Alil=A 4)935,4 0 Teter l=8 reright l= 9 8 25 (Paleo) ‘en largest 959 and6>25 (Fue) ‘Thea, lergeet = 4 Auleatd ‘Now ell MAX HEAPIFY (2) lotrotstion Now { = 9 down to 2, and sae = nize ~ 1nd call MAX HEAPIPY Ua Dose tine exchanging A] ¢ A) 7 Le a = ow eal MAX HEAPIFY (2 we pet Now exchange Aad (and see #8127 [ele [2 Te [33] ‘gala call MAX HEAPIFY(A, 0, ot exchange (1 and A (and see» 7—1=6 fia) 9. OY DO). T wD © ©© © © ©© ® a sT7Te[e[2]e iu) Sofina tre afte ‘Agnin ell MAX HEAPIFY (A, 0.9 ater BUILD: MAX HEAP is . ass ® aq a | = te K OG Ae 6 ® ca EEE] ‘wit Design and Analysis of Algorithme Again call MAN HEAPIFY (4,1) ‘exchange A [I] and A [5] and now size = 5— 124 ical ® @ ‘Nee ‘Average | Worst ble | Method | Othernotes a ee o> o's aap on jets to 7 1M (CUTSem-5) Introduction e[s[aia Taaion | Oh [Om | Yer tn Avenger Again, call MAX HEAPIFY (4,1) ies ‘exchange A {1 and [fl and size =4— 1.23 w @ a Py ~~ 6.9 cs @ © = ; on ce en AIM HEAPEYA,») Sa] conn [am eae exchange A 1] end (3 sie oy — o% ed ee ==) a Counting srs liner time cortng algorithm used to sort items when they ong os faed snd finte et call MAX HEAPIFY 4,1) balan ‘Algorithm exchange A (and 2] and size «2 1. Tet C10.A1 be a new array | © a) 2 terie0t0h © a cae zs © fj Teleg sone 5 secam—caii. Ths sted say 1 nw conti aero Smet 213] sf eT 7 [wo] uy] a] 6 forieltoh = sec coins Gea Qte 1.26. | How will you compare various sorting algorithms? 1 Oli} now contains the number of elements less than ar equal toi. for length downto ao BICAgT AU) cay -catn-1 = see Designand Analysicof Algorithms TASB CHUTES, ‘QueTBS | whatis the time complexity ofcounting sort? Mistry 1-300 (CMT Sem) Intention the operation of counting sort om area A=, 6,23, 45,6, 7 [AW [eau | mona can [enn cana] ARTURUILIE, w)s | * | ames Gi=7 ale | ames cmies ; 8 4 Bi. Cale 3 Time complexity of counting sort is O(n). = Wea a parsers sw 7,6] | aoe | cars AGELESS) eje| a | ames ce steph: a args element nara eel eae aes oizsess staf | pmes cole ys, CREEL afa|2 | eaes cat | 2: J Tto10 Jeng =10 eae Ctl < ClAt +1 ae = eee Ie « Ferjat rfa fa | emer enieo ote sas 6 1234567830 CAM ct +1=041=1 ¢[ofsTofofoTofo] f Guar eetretes ofBlaTeTofoTeTo} sEDIssislss1e14 Bejot Tae Tat]] write the bucket sort algorithm. oissase s CU ci +t-o4181 ofS ToLeTaLeL fel cise 1 The kat sr iss to dre thine 1 nto meq oizsese ‘bsteray or buco, ad then te ape brs ia Siniaryforj=5,6,7,8,9,10 c fo]: oT32] 213) i beinet Sepa 2 Sic the lnpsta re uformly rbd oe we dosotecent Forfeiws tna nabs el neat ake Gti oth ecu—n 4 Toprodaze the otput simpy srt mers nea bucket andthe fein > tough thet erro the Sess nes oresase 4. Thecodeonumes tht inputs inneleneat ary And enc leant cucu coe fTeLST=T=T3] InAestufeeOcattet Weak necdenauslaryaayBi0~ t-te cae te Take tock) Fee BUCKET SORT (A) arias acaiaie. Lm length Ua cae o@i+on) ¢ PLTLs|2|3|3] 2 Prieiton cea O123456 | do lnsert Ali} intolist Bil nall|} Siar fri, 5,6 0 OTT S|ST 9 | Foricoton-1 eet | assert Bt withinvrtion sort thd ‘Coneatenate BLL, 1. Bat] together in order. Bowne a a, hn it 0, capil cau - Design and Analysis of Alorthms 18TH LCs Sem 3, ‘QueHSO.] What doyoumeanby stable sort algorithms? Expy, ‘with suitable example, Taswer 1 Aortng algorithm e gi tobe stable if two objects with equate, ‘ppear inthe same ord in sorted output asthe appear in the gt rortedarray * 2 Astle sort isone where the iil order of equal items presen Some ortag algorithms are naturally stable, some ar unstable, ng ‘same can bade stable with care Stability Se important when we want to sort by multiple felts, example srting list fas assignments ist by priority and then ‘signe in other words, assignment of equal priority are sorted by sssimed 5. Onocasyway todo thsi tosort by asiguee firs, then take the resling carted it andcor that by priori. 6. This only works ifthe sorting algorithm is stable-otheris; the srtednee by assignee of equal parity tems suo preserved, 1 Forexampla, fer the word apple tre” and pik” by length the “tro pink "apples astable sort but pink tee" apple se 8. Mergerortieavory common chive of stable sorts achieved favouring ‘helena tem in each merge step onyiftem right item Je put eight a). 8. Radixcor:is another ofthe stable orting algorithms. ‘QuETSE] Write a short note on radix sort Tarwer 1. Radix sor is a sorting algorithm which consist flit of integers or words andeach as digit 2. Wecansart srtingonthe est sigiian det orn the mos sgt, age 8 Onthe frst pass entire numbers sort onthe lest significant digit © ‘most significant digit andcombine ina ray. ‘4. Then on the second pass, the ete number ae sorted agin on th second leat significant digits and combine in an array and 80. RADIX SORT.) 1. forie-ltodde << iCSIT-Sem-6) wea dtale orton array wn dig outing wt wld the jb ‘The cole for radix rt assumes that each element in the w-element tray Abas gts wheredg ete loret order dig ands the Fite order dg. Analys 1 The running time depends cn the able wed aan intermediate mating sige. 12, When each digit iin the range 1 toh, and is aot to large, (COUNTING. SORT isthe ana hie. 44 To case of counting sot, each pas oer d-digt numbers taker Gtx + Dtioe. 4. There ared pase, othe total ino ordi sors i tie. There rod puot, othe ota ine far rad enrt dn» hd When Cfnstat ed k= fete adc sort rset. For example: This exanpe shor ow radix artopertesenseven- giemomter Introduction ‘Tablet. Topot [1 pass | #4 pase | opens = mo | mm | om ro gs | a | as sr ae | os | as so | eo | ge | or 86 = | as | sr 0 mo | cr | mm a8 ss | 7 | so fn the able 191.1, the rt column ithe input and the remaining tows the it afer srcessive sats on inresingy sient digits ston. ‘VERY IMPORTANT QUESTIONS Following questions are oer Important. Theve questions | |” maybe asked in your SESSIONALS as ell as UNIVERSITY EXAMINATION, 1, What do youmean hy algorithm? Weit ts characteristics. aE Refer Qi 2, Write short note on asymptatic notations. Refer. 138, 3. Explain the conce Refer. 1.20, 3. Write short note om heap. Refer Q. 122. 7. What is radix sort ? Refer Q. 131. pt of merge sort with example sort algorithm with its anal 00 Advanced Data Structure (2-28 to2-208) Parte mn ed Black Trees Bete apt Ot Par-t nn 2B A pene aed Anse’ pe Quins on a Part 2-908 to 2480) A.Conctpt Outline :Part-2 an 8B B. Long and Medium Answer Type Questions 2-308 21 B(CAITSem 2-2B(CSIT-Sem-5) Aa raneed Data, PART-1 Red Biach Tres, Butrees, CONCEPT OUTLINE: PART) + Redblack ree ‘© Aredblacktreeisabinary tee whereas ssamestraatinbte either redo Beek eur A _Ieisatypeotveblancing nay seach re + Bitrees + © Brees tree dat structure that stows insertion and delet bn Barees, ater | eps dat sored a besriticenmed a al nodes can bar varie str stild nodes within some predefined ane QveBAL | Derine a red-black tee with its propertion. Explain ‘he insertion operation in ared-black tree. “Answer Red-black tre: A rediblack tre ie binary tree where each nade has colour a8 an exis se ee redoric tuselfig Bay See ‘where every node follows following properties : ” ‘oa very nodes either rede black ‘The root iba. veryleaf NIL} ie back, ‘a nodefsred then both ite children are bac, reachode al st om the nda to decd eave cot same number of black nodes. . : 4 Iaterton 1 Weberin by ading and eloaring ted peewee the node as we doin a simple inary search ee alysis Agri a LAR (CST Sem) Desienan RDANSERTIT.?) fyeniin 2 rerot iM wl ee an Siegel < key ‘ 4 then = let el floes right plex ityeall tN 40. then oot (T= 11 eae ify ll < el 12 thenlet lez right (le 14 lo ele al 1s sight elenillN 16, colour fe} RED 1, REANSERT-FIXUPC 2) Now, fr any colour viltion, R-INSERTFIXUP procedure is used. [RBANSERT-FIXUP(T,2) Phe i= 82D 2 parcial & eye alo tess ed 5 thnebr = BLACK oan © my) mack cat 1 Sub elle nD cai t opot wie see ne i. ene cont th tarnsonare. 9 cont 22 sini mac oe 3 te cas 1k wowrenonaT ph 1h sentence wih en eee 10 colour(rontH] - BLACK RAN (CSTTSem) Advanced Data iy, eka ‘hencase Lis pplied. Case 2:2' uncles blac, # Is the right ofits parent : i 2 Change toz parent. ‘Rotator’ parent left to make cas Nov, n this case vielation of property 4 occurs, because ule y ise, esien a Analysis of ithe La RICSTT Sem-5) ne :a'sunele I lack, = the lat child of ta parent Set sapatent ace . Rotato2'sgrandparer ight. [BST] what ar th advantage ofreduc ue verbaary search re? Write lgrithns onset Ttacee tree 4.55 reall [Advantages of R-tree over binary search ree: 1, Themain advantage of ed Bac res over AVLtrees that sacle {opdown pass may be wen bth insertion ab deletion operations 2 Redback tee re slftlaning when the therhand simple inary earch tres are unbalance 8) Wisparticlrty wef when incr enlerdeletes ar reatirely eqn. 4 Tie compleiy of rod acktreis Oogn while onthe cherband ‘lnple BSThae tine complexity oF. Algorithm to inserts key inared-black tee: Refer Q.21, Page 2-28, Une. ina red-lack tree Nu ical: inet: OF Sean Advaneod Dat Designand Analyitof Merit PARICSITSem-5) osert 3: =. Insert: VP aeass I Insert 8: ‘ReeASTT] explain rea. back tee Show stepsot inserting the bes 41,88,51,12,19,8 into intially empty red-black tree. (ATOR Marea on Mat is red-black tree ? Write an algorithm to insert a node in at ‘empty red-black tree explain with euitebleexamyl 2SB(CSTT-Sem5) eviga and Analyt of Algeria aie Que RA | tosert the nodes 15,13, 1% 16, -edblack tee and delet in the reverse order of insert overt: eo roe Date: 2 a @ @ to -'S for @* Ge Datete6: @ se Date: ‘a, a Date *® Duet: Nowe ‘Gee2E | Explain insertion in rod-black tree. Show steps fr inserting 1, 2,8, 4,86, 7,8 and 9 nto empty RB-tree. (ARTO OTE, Marks 1 ion in ed back tree: Refer @. 2.1, Page 2-28, Uait2 Numerical: nd Anaya of Algorithm pesigna ie 2, REED] tow to removes node frm Ri-re? Disa lteset snd write down the algorithm Tn RBDELETE procedure, ater epliting uta noe, it alls an ausiiry rocedare RE-DELETE-PIXUP that changes colours and performs rotations forestre thre Hac propertis RBDELETE(T,») 2. ie) or ight =i $$ yp 2428 (CSITSem-5) AdearestDtey 2 dearer A dae © TREE.SUCOESSOR®) 4 itll am then et} ees ert piel Xp = nit thea oT x 10, ety tet 1 then ex 2 erie ox 1B ityes 1, ten keel « kel 15, copyshing taints 16. ifort = BLACK thea RBDELETE-FECURT,«) 18 ruray RODELETEAMUPG,) Les oreot and colour « BLACK 2 aeitz= ai 3 then gh 4 esac] «RED 5 enesewiel BLACK © csp RED al 7 Leer ROTATE isp See & we nti zon ict oa 10 thems ACK coer = BLACK Use pte Set 2 eteiteluighta pent Bence aes Merle ap seat 15. RIGHTROTARBT, ems 1B we righty seat 17 calor! eli) Seams | 18, colour « Bate aeuet | Semet 2y9M(CHNT Sem) 19, clout «BLACK ened 2, LEFE.ROTATEZT, pel) ewes a1, xerolfM end 22. else then ao ih ad echangeds 2B, eles = BLACK Caren ot RBAree for deetion: cue reds 1. Tccrs when nde the bing fades re 2 Sice w mathe lceidten we an vic thcners oi fl and thenperornalefaton pl wi aos Myatt redo pores The new sibling of, wich none wt tren pe to he e ‘rotation, is now black, thus we have converted case 1 into ease 2, 3 ut 4 Cam2,3and ocr weno sack Tearing Wrobunctevanlaen ‘ls, which was originally either ror bck. 8. Wedo ob repeating the while loop with plz as the new node x 4 Ifwo enter incase 2 through case 1, the new node ire and ‘ack, the original lel was red. iste and 1% Thevalue ofthe colour tribute of the new nee the lup terminate when i teats the loop condition The new ‘odes fathen cnloured black 24D (CRIT Sem) cas siblings chy use childs red, and w's right hig isbleck L 2 {Com Soccurs when wis sk, tale sred and tight cig feblack ‘Weean eit the colors ofw and itslef child ef and they pero right rotation one without violating ny ef the IA properties the now sling w aria Black node with ht cil end hus we have traneformed eas Sint case 4 (Case 4:2 sibling wis black, and w' right childs red 1 2 ‘When node sing wis ack and ight eli ed By making some colour changes ad performing ae rotation on el we can rove the extra black on, making ie ingly bac, ina vlating any ofthe red black properties, sin ant i rine __ Pan cantsemsy TATE | Devrie the properties of redick trem Show the Tai the rome soe Bee tece wih nero res bat heigtatmnt ein on the height bof a red:black tree with m internal nodes isnot Yerthan 210g (0 +1) geet en of ce lak ee BaferQ 23, Pat 2-20, i cme es ot hn Suthere are nolevesinthitree at dpth es than which ean the Soler sleet os many internal notes av eomplcs nae eee right ‘4 Therefore, £2" 1. ThisimplieaB kee nant Analyt Algpithn Aostpauyaaiey B doicist J tej eel +1 down of + 1 4 isla] and = ey 1, doc fel 6) 8 thenretarts,) a 6 ithe) Fs d 7. thenreturaNTL i dokey fel Bey eee DREAD IAD fs, eyfel = ey return BTRBESEARCH Gs )) fo, nde 02 ‘ ‘The number of disk pages accessed by B-TREE-SEARoy, 1, DISK WRITEGI tin)= loge) sbereistheeihtofthe tee and nisthenumberg," 48, DISK-WRITEL) wie eatl stim taanty evhlebop tine gs” pis RTE] cach nodes is (andthe total CPU tine is OK) = Ott ogyn) YS sed by B-TREE SPLIT CHD) The proce perfor [BTREE.NSERTIT,}) au operation 1 rere UTREE-INSERT-NONFULL 5) 2 stabi=n-1 Fi teal {tens ¢-ALLOCATE:NODE.) 2 teat 4 neti es 4 hen whe 2 and ey 5 eal FALSE does al ese & aibeo 6 ie 2 efier 6 key, bel & BImEsPLT CHILDS, | a aden 8. BATREEINSERT-NONFULLé, §) 8 DISK-WRITEG) 10, else B-TREE-INSERTNONFULLr, A) 8 eleewhile 2 and < eye} BATREE SPLIT CHILD, ,9) We detei-a 1 restocamexooe() ae | 2 tata | READ | tara | agen © injet-t 1 ten REE SI CMD © tn bayb) 3 iin © ett niet 1 theft 2. me sear Hons 8) & epenn Tel PU tine eh) Og) ® agent | 2-208 (CSAT-Sem-5) Adeaced Daan, Spy Ea nT rane anti ssimcarrsena ime a F od wrt NPA’ im semanas ‘Find median, More than hey we ‘pit bets fom etna So, we splitthe node by 2* oy. (ie, 25 kay move op) R[NTOTS] Nore than keys tol the ned fo media Insert (ie, hay move wp) Northam ye ‘oi thaole fom median mal . (Ce, 2 ey move ial wo Bh Now thm dks GE) EM EEE Moran Teye ‘nit tem om median le Median an? Ge, 2H more | SeTQTs) | GP Go ty | Weenie arama eee Betree of order 5 from the following li c 20,0 05,85 15556 95 56577515 40,660 458 Hey, ener RETA, Charactritis of Bree: Refer Q 29, Page 2-18B, Unie Numerial: 2, 90,95, 5,10, 56, 60, 25,5, 65,70, 75, 15, 40,50, 60, 45 + order=5,Mas. numer of keys = 4 Insert 5, 60,25,5: pesgnandAnsh of Algorithms 2.23 (CHT-Sem-5) Cel el) eh) ao]0 [55 Inert 5 ml ie J») laf leafs 7am aaa wf) [ass (lef fobs) (sie) Eels) sro) he RicHIR] Explain B.trec and insert elements B,@, ly F isto zw Direc Fig 2181 then apply deletion of elements F M, 6, 0n Ferulting B-ree. e) Gfx) Blo) Fst (Fie at (nae Betree: Refer Q.2.8, Page 2-158, Unit 2.248 (CSITSem-5) jenand Analysis of Algorithms os 2 (apm) Insert + E TG mae bent Rs] = ° fee" TLS ole) [xe] No] 7] be | P D i P cl[e]™ tT x 7 ill nse ae ; 2268 (CSITSem-5) Pate Ste, B(CSIT-Sem-5) Delete! 7 nix] = 6 (even) “a wane ME Sag eons so deh Gras} — =F DeteteD: Gritesrin =) tay SSS rn oT! z af ta ty pete — GSS - [x] of of do as a ty A Fn tning ttn. 50-E ny, aH cam ENMABxYD.E80tiememtyBir whinge | iw a Gr laser series nor eeoe eon atibes de-ace aca 7 tna ETHICS ja enti data ome Serene pines a ik: Inet: “TRG aa enn EIxTaI5] te (clFTETRTs) weit CREST ‘As, there are more than 5) CLFTETIaIS) kay inthis node ithe 2.208 (C817 Sem.) [oI TREE] Movethan hey sm ene aHetan= ME -$28 te, 2 key ore op) (key move wp) ica NE aa g iS ‘ei | Pao on) fam hat Insert A.B: Insert X,Y Inser.D: GEG) Ea) [ok] TER) Moe than key so ec ma Ufm > 1, then for any n-key B.teo of height hand 5) ei [ENIS) Ds) a EE ENS) ; ‘minimum degree #2: sh slog, 20. legree 22, Prove that: slog, Ge, Shey moves) a, sag aa 1 Tear contain int OS A oe fae EEE) 8 ‘Alster nodes cota at eat ke ‘There areat eat 2 odes at depth at east 2 de tpt 2 ot ast 2Soedes at depth and 2°" nodes at depth. Sp “Lay 208 comTSen5) Araceae EEE EEE REE eee eee be penn and Anat of 201nCsITSem.5) netsu-n Dm Ferien aim: aa Fri ote are Heme D Uy) eaad ‘Tocight ofthe tree ink ) Sentara 4 trrearoenely($)ie."C adel depth ifort, kta rer scaled "ona mee lee? ithe teed "noite. Het a degree (rn ands ee eB By By 5 ‘ . : fom PART-2 rete Bona ps, ose Hes, Tre, Shi in [GISHIT] Wt is «binomial hep ?Deserbe the anion o FoHCoponaeee OUTLINESIPARTSToT nomial Be CONCEPT GUTLINE : PART-2 : ‘binomial heap. inom ere! ine the Write an algorithm for *+ Binomial heap: Aioamial eapit dat, sinter || Peffrming the union operation of two biaomi inary beap ot also supporting the operation of merging? || performing ao ial heaps and aloo Ei aps quik me Sah ac ae I sana ps eens — i 5 i> insertion Binomial heap: afer 216, age 2-008, Unit 2. Rene Deranng || SSeedrvinemiathesps * Seeneane: Tera lakedlitstbeepordredtnes || 1 th BINOMIAL-HEAP-UNION grocer epee ints Roni eerie tion {gout whore rots have the same degree area a4 2 The flloring procedure inks the Bee rented ade to he a tantee i Laking Dy treroted aisles thats salts thepreatcty Nees es a Rascals + Ts akintotsarch aed ee tmanicor ce BINOMIALLINK 9.2) sateoftrings 1 poles + Spt aleeedintdit date strata eed aschoany adeley Ine dogrecl «= greta +1 8 The BINOMIAL-HEAP-UNION procedure has two pases: ‘The firt phase, performed by the ello BINOMIAL-HEAP- [MERGE, merges the rot lists of bnomil heaps H, and to = singe linked list thet is sored by degree int mvotaialy lncronsing oder 1% Thocacond phage linkr oot eq! degre une most ne ct ‘emins of each degree. Beause te inked ist H is sorted by Alegre, we can perform all the ike operations icky. BINOMIAL HEAP-UNION(, 1) 1. HeMAKE:BINOMIALHEAP() ‘2 headlil BINOMIAL-HEAP-MERGEIH, H,) ee 2328 (CSIT-Sem-8) Avaneed Daa Stig ree the abjecteH, and H, bt atthe ists they point to ited = a 4 5. then return 6 preere NIL 1 xebeadlél 8 neste sting 8 whileneste# NIL 10, doi degree # degrctnent) oF (cinglnert]e NIL and degrelsiblingoext] = degree) thea prev = tse egy repent Seam ient sei keys skelnert then bling + sblingiext=] BINOMIALLINKlaerts, ) lee iprevs=NIL then bad] next eloesiinglprevs «next [BINOMIAL LINK, next) renee seats « singe] tira [BINOMIAL-HEAP- MERGE, H,) L. ee beadlt) be besa eal + min-dogre a5) ithesdit} = rer REBBRSBREBBE thea) @)* snd next = NIL snaferinverting2, binomial heaps oad) Aegre el degree (next 2,Now nextx make x and x makes prs ‘New next = NIL ater inserting 4 final binomial heaps 285 (CSITSem-5) 2.968 (COTT-Sem-5) Head asert17: ‘After Binomial Heap Merge, west , O—®—® @ degre l= degree [nxt] degree [Sibling (next degre fe] eye sia ert] 4217 M So, O-@ nd call Binomia-Link ext] Wem o—® ® © ere « ers et Sing fests = Key et hey ter] ale evs =NIL then eed «next Binemial-Lik fe next} nd Analy Algorithens ena tH) (2). next NIL @ for iveting 7, na boom heaps; ey Head it -3(D, oo @ ae plies saat) ? @ @ agra (l» degroe next} ‘Senex males z and next< = NIL, and after inserting 1, binomial hespis: Head +@—D © @ Insert 11: ‘Aer Binomial Heap Merge, we get sgxan posi Agri 2-898 (CSITSem-5) es O— @ puaeresaaoor) degree [Sibling [next] + degree lel eye — = ses roani {2) OG) ® eaattt-<@—@O—§Q 6 90 © degree [x] « degree [next-x} ants x next Settee toate = o—9@ ‘Sitar oper erg i Hea h--@—— 6 90 6 0 6 deg ele degre ner] : 5s ng nate dere ® Wye slay bere tel x ib > ‘ waamt-+@— Gp O-3—__ & 60 © @ 60 degree {2} = di 8 bi dere feeders @ ere apie Segre ieee tl say Bats a revs NIL, tegeeel = dere (ne) Sing next» NTL ey sey font Ee eae si tsa So A © 6 ® oom Seer Pot aa +@—) i 6 @ : © 0 eerste = degree [nests] ® s,no change and this ithe final oma esp ater inserting 15. Bae H aT] wat Fibonscst heaps, Fibonacci heap? Discuss the applications 241 BICSITSem) of Algorithms ossarsasss tN FF seaplane of minbeapordered tees 1 APs ee al te bene 2 Teens * nodes may destroy binomial construction, Dealt ‘nimi FO soc g rate dateieme gt Ronse Minimum key. Ths nodes called the minimum node en aeenii aempaere nc beapi sed fo Distras algerthm bcanseitimprovesthe Tete Sa stra auger oan cok te Y What is Fibonacei heap ? Explain CONSOLIDATE fori «Oto init) oat oN {foreach node win the root list of degrees] ‘mil Ald] eNIL 1 2 a 4 drew 5 ® 7. doye-Ald) » Another node wth the same degree 085 | 249B (CSITSem-5) Advancea| Patsy, 8 if keyle] > keybl Sy 8. then exchange 09 40, FIB-HBAP-LINKIH, 3.2) aL Ald NIL | wa dedet 18 Aides 14 inl) “NIL 16, fori O10 Diol) 16, doifalil NIL | 1 then ad@ Ai tothe root ist of 18 ifn) = NILor ky (Ail < kept) 19, then ial) lil FIBHEAP-LINKG, 9,2) 1. remove y from the root ist of 2 rakey a child of, inerementing degrees] mark « FALSE ‘GARE] Dene Fibonacci heap, Discuss the structure Fbonaci heap with the help of a diagram. Write funenas | ‘ting two ibonaced heaps, a Tarver Fivonec heap: afer 20, Page 2408, Univ. Structure of Fibonacci heap 1. Node structure: 4 Tefld mai Tri the node hat st eid Seceacllofantber aude hse them 1” Me el "degre cataine the numberof eh ne he number of eden of his ‘Thesrcturcontans a dulp-nked toting sade Nw conage en Send by poate mini tothe {ech et emg ae cal ti pesgn 0d Anas of Algor lf: Nur of noes in eap Hf lt Kat ‘Fig 2200, tea a for uniting two Fibonacci heap : FID EAP-UNION(, 1) He MAKE-FI.HEAPY) il «mit Coneatenste the rot it of with the ost st of iin = NI) nn NIL i) int) tin i) fhe mt ni Froeth objet, ural i Make-Heap : Refer Q.222, age2-428, Unit i Inserts) 1 degreetel C0 2 pid eNn, 8 eta) 2438 (CSIT-Sem-5) Discuss following operations of Fibonace! heap: sumcemsm Moma 4 defies —~ 8 ahs ks = AIS F icreritcnaning thet Eon 2 enh e fe CON) emmsman ones in amen : Fer tthe resign nt Fen anna tense oni) = nS see se So teamed 60. +199 A Mine Ironman Ponape Potehayel ern tne nian ‘Hoe’ Beas the patental of doesnot change, the amortog ‘Mion en otkoanl con cy se DAP ERACEMIND tenia 2 een 2 ttroh se 4 teatro © phen ‘ : : removes from the rat it of Meerighte hen al NL 8. dues «righ 10, CONSOLIDATE) 1. te n= 12 returns Rie] waat ities 7 What are the propertis of tries? ae Aue (igtal tro/ radi tre / rf roi kindof earch ree cerdered tre data structure that ie wed to store daa swocativearay where the keys are ural ering. 2 Unlike ainary sear te, no node the tee stores the kay acct with tht ‘ih ta onde pst ate tee Sefines te Be 2ASBUCSTTSem-) 8 8 common prefs ofthe sting the roots ssocaed wit he emp “ewe! I eile ache, GET Wet an ort search in heya en ee BD as ee FT eraracatin nea ee En eta a cer ae aca rooms Te erninisiap RE] wrt hip tat Wate tropa? AL Askiplists bitin ayes 2 Thebottom ayrinan ordinary orderedlinkd lit 3. Bachhigher ayer act an an exprese ae’ where anelement in yer appear in lage (+ 1) with some xed pecbobityp (Ome commonly ted values frp are and 4). (On verage ech lament appears in A1-p | (say special Head element al he oa ian etal elaine tekst inallthe it. —— 246 B(CSITSem-5) Advanced i teapot oath tase go Properties of kip it rane lent in adton pointing the nex SemiSts even furor down heist Alcea eleent that as ervaryy 5 ner ptiotbe net erent inthe ag otstlbene velZelenet din enera en, | Tint vel element. | ‘Ween nsetion arching and deen gy | suit ting ‘Anewer Insertion in skip ist: 4 Wowil start rom highest evel inthe ist and com the current nee with the key tobe inserted 2. Iay of next node is less than key tobe inset moving frwardon the same level Ik ofnext node is greater than the key tobe inser the oater to current node at updatel and move continue our search, ‘Atth kel 0, we will definitely find a position to insert given key Inset, searches) | lea patel. MaxLevel} | relist header fort: = st -+Jevel downto do hile forward +key forward) plate se Fes fereardlo) Ini undone) ‘tint ists eel then frist seve 1te de pda: t+ header 1. tet -steel: ete 4. xe mibeNsdet os 38, fris~Otoleelde “te pa sree emmy lem ay, PATE KEY tn ed Chon we eg led then wy one leveldons perneaeeee chy, vale) pis of Agorithne 2478 (CSTSem-5) sentation sapdb es ih bo wax fora) 508 Ve esarciey then return x valve sal Del alupaatlo- MaxLevel] 1 ialis header 2 relist level down to Odo 8 erred hey forward a Tine Sere tor t ‘ o * 2 3 ffs key = sarchkey thea, fori: 0tolist evel do itopaatlil > forward + then break. patel) > forwardil =x» forward frees) hie ist level» O and ist haador-> forwards -ovll = NILdo at rlevel-1 steel ‘VERY IMPORTANT QUESTIONS, jing questions are very important. These question ‘may be asked in your SESSIONALS as well as UNIVERSITY EXAMINATION, QL. Define red-black tree and give its prope ‘ame Fafer Q.21, 2. Explain the insertion and deletion operation in a red-black tree, ‘Aux Insertion : Refer Q.2. Deletion: Refer Q 26 saan comTsond — seen meen OY BC of arig nh ae ana ation. der mek ax Bards - ‘pnt nrton and lation op a Ble tn eee 28.” ny Deletion mn + Refer Q. 2.10, tn qs vos nine 9 7 Desrbth wn io ax Bart qs. Whatistsies? Give the properties of tri, ‘aa. Refer Q. 224 = 7. Explain skip list. Explainits operations, ‘xB Skip ist: Refer Q 2.26 Operations :Refer Q. 2.27. ©68 Graph Algorithms i (9-28 to 2-128) ‘A Concept Outline 2PArt2 wun $: Long and Medium Answer Type Questions soem (8-248 10 $408) Part ences ‘Misia Spaning Trace Prin’ ond Kruskl' Algorthns Single Source Shortest Poth Djttra'sand Belinan Ford SB 2B A.Concept Outline : Part on: Bi Long and Medium Answer Type Que S-1B(CSIT-Sem-s) SAR (CSTTSem5) i: PART 1 stand Comer th Bop th tei eet on Contes Hl, Searching, E+ PART: CONCEPT OUTLIN! raacea' algorithm for matrix multiplication: 1, se ee and cemaetechnier Spee ws, spetin et Cn al where each Ay Bad Ce teres homing at ni 2 2 i cme, Band Chto fur 2 =a mee see melctonateetces Vanden 2, | 1 ean A Satria Serah cBFSinen eri re Breath mtgondrecederondeced graphs iy | SSonetpahscwrb algo = DTS Pan ir Seareh) I lo tree searching SEES een | | __Stereedverenv ‘Bubble sort: Bubble Sort A) 1 ferf-» 1tolength lt) 2 forj- length [Al down t+ 1 2 way d we ‘may end up witha aot opinal sation. ss SAB(CSTT Sem) GraPh Agri, Depth fet ism epecil ease of eptimited earch, where, Algorithm ‘depth = max depth toeareh 5 ‘state “ea eines ten retorts de se agenda ot emoty 2 Three onto: Tapa te cdot ten a odes opty operant node; Sue dato et of aged {inate new es then return elton) ‘QCA Feplain Breadth First Search (BPS). Give its algorth ae] Breadth fist search : 1. The general ea eb aBreadth frst search berinning st starting ‘ae ial: | Firstwe cami the starting ode 1b Then, weexamine all he neighbours o A, and vo 0, 12 Neturaliy, we need ta haep track ofthe neighbours of «nade, ani wy ‘oad oguaraate that no node processed more than one .Thissccomplihed by ung a queue tobold noes that are waiting y ‘beprocessed, and by wing Gold STATUS which ells us the cure las of ay soe, Algorithm : Tis lorithm exeuto breadth fist search ona graph @ ‘egcnng et ating node A : 1 Taka sl nodes ready tate (STATUS=1). Futthe starting nde An queue and change it status tothe mating se(STATUS"3) Repeat sep and unt queae je empty. Remove the rat sde Wf queue, Proees Vad change the ttaeof ‘Noth prosesed ste (STATUS = 3), ‘Addo the rear que al the neighbours of M that ae in the eeaiy Sate (STATUSe1) and change fir satu tothe wating Ste (STATUS =2). we zi Bo ftep) 6 End REESE] eplain topotgset sort Give is algorithm. seo even and Arby Alois sén(ctiising 4. Ateplaler of Directed eye Graph DAG) ran ordering the vrcesot T rch that fr ever ebelee) we have op 44. Noplogialtorts alice oderingofalita verter tin 3 contains nee), then appears bf ate DAGiseeitheno ines ordering igo nn wn HE ‘A taplilerdeving i an ordering ech that any ced pth in 8 Ao eaves veces in ineecep rin aa sort) TP or enc vertex dhe Bie tne by caliog DESC, J ner ech Sed vertex it theft ake et Hour th ished i ‘Weito am algorithm to test whether a given graph is connected oF not. ‘Testonmected (0): ‘Choose a vertex ‘Mabe sist of vertics reachable fom: fed another it of vericos tobe explore Iaibaly,L=K= tile Xie non-empty Find and remove some vertexy in foreach edge 9,2) teinnetinL) ‘ds ob Land {ELhae fewer than nites return dconnected lee return comneted. piste ieee ere algorithm. pperaeere 1. The Strongly Connected Components (SCC of directed graph Gare ste roaimal trongly connected ebgras ‘i 1 tteach strongly connected component i cotrcted to ain verter, the reulinggraph ie ected yl grapalled axcoadesation of a.

You might also like