You are on page 1of 22
bstract Data Type Aestancr Dararver + Qa abit datatige 4 0 cotlerbion of deka ond set of operalions on thik dota @ Stack ® Qewe @_Lronzo bist @_ Broney Ber Ste A Risk corkaiting several Rend oporofting on the Rosin fied out” Cuardy pense + Toms ean be added to the stack (Push) and renewed Ram the sheds (P00). Tre Best ftom added to the chads ig the Rad ikem cemoved Fem ds Por.) we Pash (51) 7 7 © ‘ s 5 4 “ 3 re sf a aie . &z ES uf34 sy 27 Bp , uv — 6F STAUS. B.P = Base Bintoe [T.P = Top Bistec FE usie algoritlon to nut on item inte stack (Pash) EX write algoritin, (@ delete 0 item from shock Crp) The proceduet PoP C) yemoves an item fron the clock Te procedure Rash (¢dentibs > V odds on item bo the stock Suppose there 15 0a owoy *Nomes” and ss wed to impbement- the ctack DecQoce Nemes : Man l£: 6 FOF Sata € stodigoiator White the psoudocale forthe procedure Ren Resceovee Rise C vole: aking) KE atackpontes > 5 Then IE ctockpointes > 5 Thr Outpt“ glach full” Bsc Nome [ stot ponter J = value stackponter 2 stoikpenter +t nue Fedproceture Write the pseudocode for the proceduce POP Feocrmar Por WE stadapiiter = 0 The oukpul “The stad is empty ” Bsc Shockgcinter + ctockpointer = L atpul Nome Ustockpanterd Sait Rdprocedure Queues =D QAe contoining sereroh stems cperalny on the (int Fk Out) gecoigle — * =P QAe contoining sereroh items cperalny on the (int 6 Fk Out) gecoigle We Bed thon added is the Rat item conave Rew te queue: cf 27 ore t ‘ su Zu —er 2f 4 ore 3 & 3 g2 3] % + 74 << he +] 49 RP ’ 7” 5 5 5 31 RP & £ & a a a Queve Ortae after, Oyen ple E-P _. Front Poinbee Rp. Poor Pointer Desearse iN Ouwe + Linear detostrudure Rsk in Fiston 0 Ae then is odded to the end of the quewe and of em is Cemoved Pow the Romt + All lems are kept A the oder they are entered ~ FRM a Head panty ond 9 Bi pany O)_write algorithon to ings’ on item into Quone D1 wwite olaeritty ( delete 09 ikem from Queue 1 write algorithen to_inyst on ikem into Ques 1) write olgoritim, (2 delete on item from Queue + Te quaue is stored as on oxtary TReviag Qatu Problem jn Quewe Freot Rear Printer Pointer condition Por a quene boeing fall is tut _reocpointer Should point tovords upperbound | maxindex | Yostinder / 7 og <5 Ee a En Ee . T Fgeot Rear Printer Pointer deqyene () dequeve () S Froot ts ay Biker according to the condition of guene being Pl is still bre Souatiow Freat- Reor fort. Pinker (®) When a student prints a document, a printjobs created. The printjob is sent toa print server. “The print server uses a queue to hold each print job waiting tobe printed, (Tre quove is circular and has six spaces to hold jobs. ‘The queue currenty holds four jobs waiting to be printed. The jobs have arrived inthe order A,B, 0.6. Complete the diagram to show the current content of the queue. ‘stan Pointer End Pointer alsa} oOlic 1 (Print jobs A and B are now complete. Four more print jobs have arved in the order EF G,H. Complete the diagram to show the curent contents and pointers forthe queue, cP ee €la[ulo [cle 1 (li) State what would happen it another print job is added to the queve in the status In part (oxi. fio, ee swessage " (WW). The queue is stored as an array, Quewe, with six elements. The following algorithm removes a print job rom the queue an returns i. Complete the folowing pseudocode for the function Star romwrer, Se amt Remove, HoT Oe 4) (0) Explain why cru queve could ot be plemented asa sack. B. clads Rsk in fsb oul able a queue is Gat in fnfel. ta Quewe them im ferd Pam sherk ond in shade len Bemoved Com We ed a ‘2 The number of cars that Coss a bridge is recorded each hour. This number is placed in a creular _queve betore being processed. (8) The queue is stored as an array, ¥ _Adarequeve adds a number 10 the queue. variables. —_— wr Ieserbe how o number is cemoved Grom the cicobor queue to be processed 2 = Wi Whe stort pointer coaches the end of the quene , it bewmes the index of the Grek element io the quewe, Ghedss_f the aculor queue is engl IE cot empty, cebwn the value at the gosition the stort ganter then increments the skactpainter Creaking a Qoked Ost oP, C\-= }—>| Te - = = = 7 nodes Gorstonk olloointer = 0 ( Hinder chads with o ot orray then =) “Wee List Node Decors Date = tring Dako Pointer Qed Rootes. Tlegee 2 Ewnryee. a uy ¢ . 6 Dedice List. esr £1.73 oF Listnade 7 Froceowee — Tnticbine () skortpointer 2 rwlhenioter Freebisteoinhes = 4 skortpointer 2 rwlhenioter Fredlist pointer =< Fon Index st to © List Cinder] punter = indert © eas List L1]- Pointer = _nubipeinte fe peeoct ove nding on tem ina Qinked Ot. (b) The club also considers storing the data in the order in which it receives the scores as a linked list in a 1D array of records. ‘The following pseudocode algorithm searches for an element in the linked list. Complete the six missing sections in the algorithm, FUNCTION FindElement (Item : INTEGER) RETURNS ...UMTEGee, goiinter cover & > wanrosncer CH) Ceated ead gh tw IP List {CurrentPointer] .Data <>... Le. corcenttointer « ise -autenkpenkte _) eointer tnetement—et—parter————— x ENDWHILE fentPointer « NullPointer Ren currentPointer END ‘TION (6) Tncaewont In Porwree Point = Let L Poiat"} - Poinker Dot Pointe Tosert_a_asde. SP at |e fo feezs 2] 9 | 3 xn 3 om * a Procover —Tsertnade ( Nowiten : sting ) le feebistpte <> nulpriates WF equed Uo qulteointer an Qrtes Qi Ca Then fF Newarbepte = Feebitpbe STORING LitLneoned cpt}. Dake = them Fest chore ond then tale where to Li Fredlatpte = List L freckist te} «Porter met Wicnodeptr = startpoiater While Thisnodepte <> nullpsiotes God_of tab nob ceoched And _List-(“Tisnodepte 3} Daa << New ikem Asseanting order Seaman J Fos Tue Reeiousnodeptr + Tranaleste Teng storing so valve vat Lest Rscrrod / This nolepte = List Crignodepte J Pointer — AE Prehounolerte = startpointe “Wren ‘nserUing sade ak sort Esc Crrewnotepte | Pointer = Stoctporntes CHAN XING 4 stortpaynter + Newooler Pee - lowenveee Jan este stattpeyntor + Newsales Pee - |PorNTERS FoR CORR LCT Sse insect newnee fw previous aed end thd galt PLACIMENT lor WOE List Cov ewnotepte J) -Pointer . List CPreviousaderter} . Potter List CProieusnalentr 3} -Pointer = Noderte Seow Enous Canpnouuee. SP CAA Descre A Noor Paoveuss Detetenate ( Dobsiten + gheng) Thisnadeptc = startpoinker Temp shoraqe so _volue of SP ol be cWhile “Thisnodeplr <> nulgonber start from eginaiog, { Aun List CThsnodepte ]- Doba_e> Daleiten atid doke aot found Waa J Peviannnde ghr = “hisnad eple Bmp storoge so volve ook bart iatex Wed WS W doo sin he ara velse_| ) Wisooepte 2 UstLthisnadetc]-goiate inevement inn Phigndepty value Cnn VE Thisnolestr <> nwrovatec node exist in Qat Tren JE Thismadepte = start pointe Gest ale to be Jeleted (1) Then nove. sP_ te net mole Stedlpootes 2 List C startpointer J- point oe Else HE i oniddle List [Previous adept 3 » Printer = List CrvsnPepte I - peiner Ewe List Ciwsnodeptd- Poker 2 froelatpt « Ercedstpoitles = Thsnodepte Sarvs i Pence Remove & g| A 6] 8B ale Pruviouseole ptr = 5 Misnodeptr = 6 List Cereviousnodegte] Pinter = Ust Lthanolepty) - patter Geek ponte Bi fenroe (va..) —* sP=W FRisrodepte = 3° Lar Livscolegtid Dobe <> B > Fes Qa Pernoiegt . Tha fe & Wreeenk Ke Sivas Tee KEY 2, Rilaoys stort comparing Prom He oot 2 WE bagqer vole than (oot oy Mave Right = IE swalles vabe Yoon costo Nove deft 2 MY vowe wan OU ay PvE _AigR ~ IE swalles vabe Yon costo Nove deft Bioary Wee in foron of Peray Left fentes Bight Per Vege eh ele Binoey Tree Gostrudkion “Tee _ toe. Deddire Dekin «strc Bere RightPtO + Inteqer Dedbre leftpte + brtege Ewvorvee Dedore Tree + Away Ci: 8) OF nove Feepomter = 4. Roolponter = © Fer_index = Jto 7 Tree Cinder )- elt Pie = inden 44 Tree Linder) Righifhe =O Srote rree (#3 - Lette = © ‘Aselecton of score datas as folows: 99,125,121, 97,109, 95, 15, 149 () Alinkod lt of nodes wil be used to store the data. Each node consists ofthe da, let inter and aight pointer. Th inked ist wil bo oxpniged asa binary eo, (© Compete he binary treet show how the score data above willbe organised. The symbol © represents a nul pointer. 4] pet [109 [6 |) The following ciagram shows a 2D array that siores the nodes ofthe binary tree's inked ist ‘Add the correct pointer valves to complete the diagram, using your answer trom part (a)(!). RootPointer index taftRointer Data _Rightointer a of 3 39 a if 2 25 zg apy 2 1 rreerointer | 1 4 ‘os 08 74 8 5 Es 35 Z ‘ rr 7 7 1 am e ah AlTemer Question 23 Question 7 (® A program i to be writen to implement the ee ADT. The variates and procedures to be Ue sted bem iaentiter ‘Datatype _ | Description = Data suc fo aoe node data end associated Node recor | Dat TeftPointer THTEGER | Slows index of tart fe aube Right Pointe TTEGER | Sores index of ato igh aavoe Daca ‘SEEING [Data om stor nose Tree “RAY | Atay sore nodes NevoataTven ‘STRING | Stores dla tobe auded. ° Freefointer THATEGER | Stores index of ta of eo hat. 4 RootPointer Trecen | Sexes ndex fot odo esiodePointer ZBTEGER | Stxos nde of poe obo added er Procedure ase he oot poo and fe por nds a nodastogoter nto ho eo st sareacct Procedure fo 2 anew data em in the correct pononn he nary toe Procedure thal ins he nade where anew nade tobe added Poco takes the parameter NEHER ard FindinserticnPoint 0) cise nociclias eas now node ff be added . is he dectn tho 2 PROCEDURE AddToTree (BYVALUE NewOataitem : STRING) 1 $f no free node report an error Omg Cunmratrne PROCEDURE AddToTree (BYVALUE NewOatarten : STRING) 1 Af no free node rep error ‘THEN OUTPUT("io free space left") ELSE // add new data item to first node in the free list NewiodeFointer + FreePointer Tre DNewode pointy }+ Dota. werdutodten rronctacer = Tel Feeentle)-pcipirke __ (Noureoment’) ‘Tree [NewNodePointer) .LeftPointer — ot oO 11 4 tree carrently expty 7 © Not ¢ re Roakpontor 2 ® ‘THEN // make new node the root node \Ceenrmn 6 Rartpointer 2 Nenonale ptr Store dota MLSE // find position where nev node 1s to be added rips med “Cah aig Mem eNOrF : ExDPROCEDORE 8 Seren For Te Correck Positron Mhiatoderer = RootPointer // start at the root of the tree WAILE Taiowodertr <> wullPointer DO // while not a leaf node geviouenoderer «Ti IP treefrhietiogePe ‘THRE // follow roderer // xenember this node pointer ‘TieNodeper « Tree(thisNoderer].LeftPointer ELSE // follow right pointer ‘Turnedteft = FALSE ‘Thistioderer + TeeetThisNodePtr]-RightFointer m0 _sNwIE Finding a_node in Bovey Tree SX oy findion Fadaode ( sewhitem) — Reuans Irease (n) Wsradeps = estpaintes skort ob the cok of he 4c Uhile Thisnode ple < 7 _ Nath pointer Axo Tee CTharodegte]- Dole <> searchiton AF Tice CThisnodepte) aby 2 Sterchtbun Mea Thisns de pte ¢ Tree Lthsnedegh]- Letparter Use Wired be «We LC Tinweete) + cghlponl } Soe Enownive Return, Tisredert'y Gunronetton: Drcrronney Ro abstrack dobotype esticly chores dota 10 fhe Porm of Key | value pac Dictioracy Element q Curie NO Unde te C167 CO 7) ry Pareco Voune we we be index other dakalyses | aitay boy gumertcah index tT Bidionedes ore indexed by their keys Mombus Integers jeeod si Tcan be used os fogs } Bamberg, Iakegers string Venked Bit, dace, quent § con be used as veloc Rerord debotype (velere Koy ond vee) Too Tees Oc Resvarcrrons Every Key can only appear ence within the ditkiorocy 7 gad key con hove only one value Ganens graph 1s a non-Qinear dalo ctrwkure consisting of nos and edges This is 09 ¥ npr which is wset bo implement dveded or undicede! gophs: 5 GX Undiected graph Directed graph Describe the uses of graphs 2 g bus roubes - where the nodes are bus stops and edges conned» te steps ext _to_esch her. + Website where each web poge is a node and the edges show the Qinks bla webry. Weights exh edge mmy have 0 weight Costence) y Paths Lick of nodes conneded by edges _bebwcen te given Modes ycde 1 Usk of modes rok catorn te the Some ale

You might also like