0% found this document useful (0 votes)
31 views40 pages

DS Notes

Dssssssssssssshsjsjsjsissijsdhdjsikskswkwjehddj1owoejehjd

Uploaded by

Praveen Bandi
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)
31 views40 pages

DS Notes

Dssssssssssssshsjsjsjsissijsdhdjsikskswkwjehddj1owoejehjd

Uploaded by

Praveen Bandi
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
You are on page 1/ 40
classmate Data St RUCTORE _|_ Trtroduction to Data Stivetune Dado. Structune can be defined as 0. sepresentation of dato. along vith tte associated operations | Tt ie the wary of oxgainisin & Storing doko. in a Compuker_ system So. Sotho Rees be teed efficierdh depending on the type etecmiaatructunes the [members Can be of different types 4 lengths _ ex: datastyuctise! includes _armnays. Sto Kool Queues, linked lists . binary +tyees cho Chonactexistics of idata strvelure a >| Te oils MN efsesentotion of doko in Sie effi. ae manne Dota SAwucture Operations __ || Doto. are procesed by means of Certain, operations i)| Tn sexting eQhieh appeoring in. the dete. Stra. ti} Searching iif} Sosktng iv) DeletigWal ovipimiyeq momma WH Toraversing.: Tatavesusii |skooclune Means ne vist the _ cement: ‘sont in nthe. ve ind oO pooticlilon Geunching it means, to bir clement to aiven data structure f 9 Sooing! tk means os0tan “the ehemenks tn Gstending — ov pees ty 4 onden fe { d ; i if L TnsekPon 1} Means ingodking she element the Sues dota Styuctune. tire Deleking it means delete the clement in a gen, data Ahoclune a Classification of Data Stovctunes Dota Strooclune STR... : a ais panies Poumitive DS Noo Pouimitive Ds iid \ineost Nonlinean Ds es Podnilive DS > include all the fundamental Dako Stroctunes “that Can be di Thsant ; Machine level instructions Wits i asinay Pointers , Sdroctuare union il Socne of Common pauimitive DSi taclude E ae geal, chonacten , yrekeon iv = A = OS: Ce Stnociunes that ane “hese i a Mone Poutcitive aS a a Loken Loading _paegnams ue often find LOunselver toY a. sifuation whene we Cannot aiekially determine how lenge an osmay fo os WME DH MALS 5 —|L powntt Centex the mio of elements” )- BG WeeaniC Wi elotind st “lh LMALLOS Cisinm size api D5 wes Gok \ hed at Dynnawce Memosy ALocasron a Gia ts TA te a procecoe In. Lohrch the size of dodo Strociune 1S change unto g dhe Stun time C_porovides Jibrosy-fonctions defined ond, Léralthhy headen file 0 Act iniote . gnemoay alpeabPon ae 1} Matloe Co 2 the smatloc OF Memor Alocabron method is used to sani cody ip Undunak, a pointer of type lock of Qhocate a single lange’ melnory uolth 4 guy a Void (ohich con be ‘Cost Into & Poinkor ot ony farm. Ute dynamic Memos Allocation fox 2D aay, LG. uses arinay of e ce ion to qepnesent Ou mutt dinsenstonal cacy 37 A iaabieqsotel ET TT miGjeai alt 11 t ¥ edt $0 eho ie C finds the elements ati by Jost — Oe agra Peni tol of st pointe wes) the Oddvecs on Ae any in _Memosy ‘OR S10 Ome ae eRG tay then by addin Oo i ink) 4+ 2 Potnden the iS ot yh ee ot ts How is chekenmined om SS = = **® makead Coan Cint woos -I Nb colomn) List Tok HR 1G MALLOC CX» wows * Size of CX))5 fon Cizo; 1 sows 354+) 5 GIS * Sizeot peed): Wortle 0 Program to perform _mantx MaWiplicadton sing diy nami cally allocated wt + = Osnaiys” bisikid Coie) Laem n i eviconat i? Ft bie hob ogqude Majo me oings) Ae toiled 20 stoumte tob equd Bn Bait 3 10Oles ad ot fapo Ani Pheslod bool Syntax: Stooct to.gname Ee] { Ped Srrarme£ founctfonds dakciype function? eas datatype Fonction H5 Stroctuier is a. Collection of data Heme’ wher each tems ane Identified as to its type. nam ex $s Strsoct a ink USN [20); Chan Name > Slook manks > uF We con Create oun von typedef Statement aS behous type def stovet t shox name C10); ink ages flood Sabeoy 4 human 5 Human is the name of ty pe defined by — Stovetune definition classmate. ieee a une. siweit typedet struct — Chon Hamers! 95 t bob Tink es Mou tostink Accs 4 wat Row) Sahlovuy nine idatjei idol 30 intyeans e b&_ Persons romeleer » Above extimple shows the Inclusion of dote Strvelune aS a poo of penson , atvutune Tha cere = on _-\109) 2003 Who have th Vabues 40% She date Sivuctune as Pens ON edob 1dey Ai s © awe © PA. dob .month-O4 + iia BA, dob, yean=2009; Self Refarenttal Siroctuness 2! This 15 the on Which one ov mose of 4s Components ot Membens TS Polnten slo ised | ¢ Lalyed pia. 0 le =: 0 Saletn arog chon Hs oo ubvibsloe Atios axa ral Paths Mp tawine ov Considesing the above of Stwelune J tink will have 2 compmends* dada tine ekcolunel each & Penn \ist stroctune doda te a Single Chon while link 7s potaten to The: value of link te eitthen addyess iA memo sof an instense of Wak os nut point. f 8 a fH aw 1 5-3 ae 302eaa oes a ee 473.6 ia ~1is@ stibegek ae 3) =O alll PESTS x GES is} ze S +) Si @ 292 Qui]: SE define MAXTERMS 101 Aype def Stooct J Tok Now: Tnk Cols Pak Vole + 4 terms; tenm a CMAXTERMS)> 1p 4 Cee aN es wodbhe. Cz votd moinc ) Neh DINE O= 10 -b=5+sesult=o° Fesust = Som Carb), Point C'+). 4”, Besult ) > 4 int SumCinta .inth) aL ink C=o; C= mtb; retin Cy * es 5 Stack 16 an osdesed ist in cohich insextions F Clelettons ase made ot one end Called the top The insestion ane also called pushifadd And deletion axe also called pop /wemove al The Stack works on last in fast woheve the lasd element is stack fs first element 7S Temoved _ | F | F [ | void main co iit zi a= | 3 [nk 03 4 53SEC Mlk BboBhy) oe Noid @Veq C int neem ) ie ines We = 55 Ponte Cty dg 7S even nj i ding 5 Qe thinclude cstdio. h> Voi d_moin ¢ > 2 Int ace, bate wesulks Partatt Cl enter o number’); Geant (Jud ™ / 4097 yesult= axb3 parndt (\s].d)vecult )) a ind fnoduckC tnt o- int b) ie Ink c= 035 ~C = O*%b? Betunn cy jeaa ad dotda, ii boxol bes Stack Cweote Cmax Slack Size) 2: nae debine «i MAXSTACK SIZE! 100 typedef Sinvcts ie oefttos deck al ter bat + howet = +0646 > Boolean Ts Emeiy Cstack):: topy™M Owens Boolean TS Full CStack) classmate. Bee ADT Stank (gawiiinerel A Objects: o fintte ordered Ijst with zexo ov move functions : Clements s 3 x : to¥ au slack € Stacy iter € element, | __Mox stack size € positive Integer Stock Create Cmax Stack Size) 2 Ohose Create bn em pty stock Maximum Size is max Stack Siz Boolean Ig Full CS4ack, max Hack Size) Sis T£Croamben of elemends in Stack == man Stack Size) yedhan Trve else setunn Falce rock Posh (Stack. Tem) s: = Té Cis Full CStack)) Stack Full else InSent Hem Into top 64 stock and xelunn Boolean Is Ero pty CStock):: 14 CStack = = CxeateSCmax Stack Size)) a etuing Tue. else sdunn Falce Elemerk Pop Cstack) = if CIs Empty Cstack)) vetinn else vemove and -ytunn element od the top of +he Stack | Note: (ABSTRACT DATA Tyee) ADT Tt is a dototype +hat anize 9uch :a way thos Spetifictation objects, opertaston. Te ceproted from vepst” of objects 4 Implemetin: of openacions __ classmate, 2 void push Celement item) £ Max STACK SIZE =) Cass Stat ae = tem > element Pop > St gL i iE ( nips SEED J xotunn Shot Empty 95 setunn Stock Ltop -- Jy 4 [est aco Void Stack Fullie bY! 7; He) J Pe | Cannot addelem exit C exit £0 \ REDS ab (latgede h Stack its ful, ie clement sheskeot Om recart Nothiirsa o Weis af Penens io Slack Using dynamic eo lef Shouct Ink Key [x othex fields * | —— 4 element 5 — Qlement * Stack; 2 Matloc (Stack) , Size of Cx Stack \)5 | Tok ci acity his =| int is Svea f — Boolean Is Empty (Stack) 2: top ace Roolean Is Fut CStack) top F= Capacity ~|; Note! Cieciinh(s) eee z ; { RElioc CStack, 2% Capacity * Size of C#Stack) Corban een Is, - a af Evaluation of Expyession Repsesentatton And Evaluotion of expsession 7. of qreak interest Lo Computen Sctectict “Q’ be Arithrnosttc expression involving _ Constants § Opexosions 4_operonds § operators | xX =afbyctdxe-axc oi] a= b=c=2 q-e=3 ei Ss h/2+2+4+9*3-yx2 araiy-8 & ol= alb-ctdxe —Axe = WJa-2+ ax3- 4 xa E = a = Go/cb-c #d))% Cemex © ah C4) (o- 249) *G3= Wao = = EM)» 2 eb e2 a 84, Z a Evaluating of es pression Stand ond vo of coriting | expression TS Knovun as intined “notation Where binasw openctoy ts placed tn between its openands s Nimp Tafix Notation is most common way of expnession itis not the 1 vse byYcompilens to! evaluate tas ey pressions Compilens we con used Rona nthisis Nolodions wefexsed to 0% postlix, ints Notation each operator appears oHen its © persn ex — talix 2 (Oxb. ex postfix 2 abx« | Giad*a Dts | SG Ee x 2 Bare3 R-- Br1>> zw E => w= tx VQ ape EC Seek eat | \oEt] i Bee \ I ‘ dentate? of Ded Srvc ine axblc ye axb Sab* atk abc OMCo=ctd))* Ce-a)e o)b —C4+ dye -ate alCh-c+d))* % 6 ot ¥= Ce-a)*e = estes o/b-c+4dd) * Ca-C* -abc-dtlea Able —dexac% x @ classmate Token Operator Precedence _[Associativity eG function colt f a U aspiay element 4 lett to vight = Stsvct oF Union sat increament decrement] 16 [lef to vight = decrement siincte ment? | q ! logical not 20 i Wl = Ones “complement Is right-to-left -+ Lneoty teins O4 plus gx addvess ovindiecion eat Size of Size Cin bytes) | Ctype) type cast 14 ‘Tight to left sel le | > Multiplicokive 13 teft to right SV kinosuy add ox subste 12 «| teftdo right << >> shift FM t|leftt to sight aeess eee nla tet toright eal i Pane equality q left to aight & <> bitwise ond g left to right A bitwise exclusive o¥ a left toriqht 1 __bitwise o¥ 6 lett to right ak logical ond “S.- | lef toright I logical o¥ 4 left tonight Oe Conditfonoh 3 xight tolefy aighttolef t xt left 40 xighd Inftx to Postfix Algoatthm Thenollaqaneninmltaes paccicing postfix from a | infix a as follows => fully Qanathis the seiuetian —|| Move i 9 Nace thei ae ing oes Vesey stale Delete at QArnee 4 => abew+ Voken| sey | postegal To Oud il a oO oe ° ab Pa \ ab * \ abe axCbtc) BA Array Repaesent ation Of Stacks —— 2) Stack may be Bepresenks Tn.com plater in Vastiou am Leary ley Means, vsvally one saat Mist 0% lin eee = || Stack will be maintain by defautt using a Jin Osetouy spl eS 2 », . \ odie | A peintes, Vastfable top cohich contains a loc ol the top ebement of the Stack. The operation of an addin Wrimlo a Stock ‘the openotion of fem wemoving Jrom the Stack | regpectively vstng posh aid "pop fonctions Recursion = Suppose | PBIBWGU or dee dan eae os dunction Coindos t etthen call function self OY CAN Stotement 40, Second procedune that Moy eventin: sess In & coll Statement back to original Proce dine ‘p? then Pits catled a vecunsive Proce dune pps A mecunsive procedure must have pollevsing Steps; Then must be certain Crifexta, base ‘cxiterta Jor Uohich the procedume doesnot coll self Lach Lime the prodedune does Colt Ttself Cdisecth or Indisectly) 4 must be closes to jhe base Gi classi (DS date Da Peat Queue 16 an ordered list in Lohich insevtion and deletion takes Place ak diffeserd ends “The end ot vohich the new elements ane added _ i6 CoMed xoxe end, and that fzom tohich ehements are deleted trom end. The tisst element inserted into the queue Ts S inst olement 1S Yemoved. hence queue 15 culo Known Os fist in divet oud list. i lL AMustrotion of Sequence of events : A. AB A aiBaG Bee iS am Ah fi t Just tf ify do ere, Pay f+ % leetos Hb Insert Dnsevt Dede delete “The wepseserdotion of queue Usually ly Means One oa lists 62 \ineon coer | defautt each of queus will be maintain Blac SEieieos arnoy, 4 ae vilisely theaoarg sit 2 pointer ‘Voriables 40nd sand yeas: or Queue Obsecis: afinite ordered list with zero ox Mose elements = functions: ag fox ath queue 6 Quever; tem E eleme mox Queue Size é positive inteqeY. Queve Create Gnox Queve Size) +2 = Crecle emphy queve whose 1 @Xtmu, Size 15 Mox QeeveSiz, Boolean TsRWOE@uene PRP teens ise. VE Coumbex of elemehis in queue i= elung TRVE else welina FALSE! Queve Add @ Cqueve item): CIs Fu @Cquevey) qveve Ee hee else Insest tem Saree of que and detmn BooleanTs Empty Q Cquene) ss = At Cqucve == Crete @Emax Queves i ze) etunn TRIE else vetian FALSE Element Delete Q Capeve) 3 = i€CTs empty QCqueve)) Sal else Demove _ Ary Deluna the item Gk Jpont oF queue =f#include z Stdio.h > focludez Conio.h> af define MAXSIZE |o0 ~ Void mainc > L peta ink :Queue [| MAXSIZ6]; = int al Pi C"enteythe number of elements \t”); Bf CNR 8nd; UY Tnserting elements into Queene BD: fos Ci 0-1) 2 a it E podndt U-@ueue ts full \ n> 4, lovea ks 3 ee Hiso\t Beant zx. SECM od". & Queue [mean] ) + 4 ol) fsonkt+ UDisplaryy ot Quene dements | pouintf(\t Queue elements ode! \n')> _ fox Cie fronts i INFO = value; oe 3 : : a i rhe Cae FIRst y PIR Conlort to furxe Erest= Pre 20] 30) ] [ero Jaraveisa) and drsplayiog a Viet linked list Tata infowmation we have -|o 4waverse a linked list fnade Node -fmom inst node until the end ef the “si 15 yeached Arraversing 0 {isk Invelves athe following. t a Assign the addsess ot _\inst a too stp be oo Node cated og PTR : I j Ss display she infesmakion hom IN Fo a of tl node > 4 #| The funciion traWerse. L fae I \ Avom left 4o right f a i ar gf — i vei display C> a | PIR = FIRST) Fi : while ( PTR! = Nutt) = (ihn fa aa = ointh CMs ds bre nro) ie 4 j PIR = PTR NEXT oulov oF i tt i : , 7 a i i z ay FTX 3 y i j Noid delete > na L ‘ PIR = FIRST; Ll hondee ere ec T x pf C'-Ld*, PTRo INFO): Dat palaetb Une a yavp te 1 ndibna eater ee ee fon APIS 2b a, Noid dedele &) x CAvoct Nope * Loc | x p7R: Ink ey 5 oie geonch Cwren d5 Tt CLoc= = nutry SUennngs HAI if Cloc == Figsr) FURST = NUL; he ed fox CPTR= FIRST: PTR—> NERF) = boc ; PTR = PRNEuy 2 L PTR NEXT =LOC>NExT - Be: Js) Hhusin (Lot INFo); 4 ) HeapeR -| A headex linked list is. linked Its uohich aluoay Cordain Spcl nodes catled o headen node ak powgining of list E “Thene ane 2 kinds of Loidsly ‘used peaden [fst k > __Goound readkeen ak D>Sx Whene Bhe lan nod contains a last pons > Civevton heoeker ligt Where the lost node poirds back }o the fh. | > [Fist | LOGhos 1 dy aS Pel fel Je el {peasbinides Searce Mateix Representation Usina Lan ceo Lis a6 oO], = ET io fe val $— 2] g ESE [oe [rn] b= [Te ee \-3] to Lol Tru] TeTau] Palynomial Representation Let us tackle os weatonably / Complex’ Problem Using Mnked list. This problem, the-mani puladion -of sy Moshi “Polynomials; hos begome a Classic exam ple OF fe Processing .A5 we wish to be able to present aay ae of different | poly nomt ols, as io os metlorysie exotnlelans general, ou Gaon} to vepresent the polynomtod™ | 1 AGRE tag een aces? where the Gj ane nonzero Coefficients 4 the e one Remmeded ve INEGI &x ponents Such at classmate Pee EEE QE=0 Ee 2 Gra} 7 Emin 7 === ee, FO We represent each f Herm ae'a mode Caijaining coefficient & exponent f fields, 0s well os o poidfen to the next tes Assuming that the coefficients ome inteqens, the _ cl 2 ais. the type detionationg one + 0 +ypedel struct polytode ~ Poly Pointer { | Lupedef Stoves f | 1d coef; int @xpon; poly Pointer Vink: Y_PolyNode: \poly peindes ob} We dian PolyNedes a3: | coef Jexpon [ink] = Boutt Dn? + | oe Suit — 3xn?+ lone sola | eT Foie 1 a b> [ale] Esko] + Lel ete] Agee padd CpolyPoirdey o, poly fainter b) /x 290 _o& polynomial _vohich isthe som of a > ondb *Z, poly Pointe c , Fean, temp ; {nt Som } MALLoc C¥eon, sizeot (x se0%)); C= Feons EC vohile Ca 4 4b) Switch C COMPARE Ca > expon, b> ex pon) ¢ Case -4: /* arexpa < b> expo */ attach (b-ycoef ) b= expon, & sear); b= b> Jin it: break; /* a> expon = 2 Som= ar cock +b? Coe if Coum) attach Csom, a7 expen b= b> links bs coset : /* a>enpon > Gre 2oa oktacki@aaicoethy, Gn expan Rae: a= aatink; a 4 * a eae seswicMmOne naan onn Ts) bx fovC;a;azoo link) attach€ a-cocf, a> for(j bj; b= b> tink) 1» Cb? Cocf,b— © ~vean ~ lin k= NULLS /® deleke extra intial node */ Lemp = G5 C= Clink; free Ctem YY tun Cc; classmate Model 4 _ wees A Tree 1§ a finite sek of sone Ox moe nodes such that these i _o. 5 pecially aa took } “The vematning nodes ase pesdiciant into ins iefoind ects! Ta --... Th, Whene each of this Seis tsi twee Ty ~~ Ty arte Cotted. sub tiers ot he soot ao . __ lev! fale oof level Tes, el eed key Touminoloaies. herivacial i 1 So ero E =| Node Stands -fox item of information plus b hos d fe In a above dragzom the tree hax 13 nodes Degnee, the number of Sublsees of Anode to atin its deanee degre of Ais 3. Bits 2, Dis 3, Cis [> leat node eee should be “0° Leaf node ov texminod node + The nodes which have deqsee zero. IK, LL.M. G.I, T ane leaf node IER creer aD coven eminence the ponens of Dis A she chi ldsen of Same Ponens: Ts coated ene Nine se Aion: L =P Degree. of a Tee ¢ The maximum OF sthe _ Ric Gotan oal Semicmathenmicee ake Ansicstors } He Behe The ansistorg of a node Ov Ql the nodes de ‘the _poth fxom sock, to thot node Ex: We eater of Kan €,8, P i. Pe otter of G ore AVS oe | i The level of a node to defined: by letting ‘the 2) Teste be eo (Goa, eon Ae cthan Lits childten ome ot level 1e 041 \wao Wet oR depth ee The mrommum level of cana node in tree Representation of Torees Hhene ane several uo to draso a tree One ‘useful ody 1s 2epfeddnting asa list O' aof ko bi Shor a He _infoamodtion inthe toot node comes first followed: by & Viet of ‘subtrees: of that no classmate Date. eDEEE BEL FLT) EL PEL nel fem] ol Fig ©) ist Representation ot4ttee Left Child Right Siro Representodton “To Convent any tree to left child Right aibling med jel Note > evesuy Wede hos i | aimost ane left child 4 atmod one closest be 8 abbloight sibling an i . J Sat enoal boked om e above Fig @ ithe left most child of ds So Sago 1a B_& the ight mosi Sibling of Bis c Be ad 4 : J v erin on bi Feet od to tebor + WBacteadmib’ ao2eu _— snotty sgegsh) + [osed wslLoaicl st dnsasea gobon seth sot2 oF tin wer . : 1 14 {PR 3 NS | Winaan Totees rect is Pavle Ta ie node fe atte empl] om consist of root ond two disjoint ial tree. Right 4 lef Linas tyee. = Pa ropedies of Binosy Trees The maximum number of node on ‘the level i cof thy nox see Is 98% saa ate 2” The moelnumbes of nodey In O (bins eevoh depth _k Is bor te ae cow ot the nom Bee ENS Ginonuy Taveli oar tisnlin dle 2e depth kis complepe it an it is Coxseaponds to the node Numbered 14 xom the fg ten of depth ic ie “the toee is seud 40 be complete if alt its level Accept the lost one have the maximum num ben of Possible nodes & YoU He nodes od the lost level cuppre Oa fan left Os possible Binoasy Thee Representation Pow sendation: We can Use one dimensional. os to Stome the nodes. psesenk to Binary tsee_ E pafeielst Hes eaNEM tts | al oo ile el Packages Yo trecte package package - a Kaq Cas node tindim i“ wher \Zi < 0 a Se hove Menke nati llisllacWad iga th vet theo ‘tis ot} aoc & hos no Parent. it) Left child Ci) is ot Qi if gizn Wi) Righkclild Ci) 1s ok iva if aren) A) Veelan on 2 8B, 6). AP t eG 3 pate = rE seamaeiele tee ts | 11 ipa Alel je D E See

You might also like