Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

DSA NOTES POST MIDTERM, Cheat Sheet of Data Structures and Algorithms

notes for after mid term

Typology: Cheat Sheet

2020/2021

Uploaded on 07/31/2021

naman-jain-25
naman-jain-25 🇮🇳

5

(1)

1 document

Partial preview of the text

Download DSA NOTES POST MIDTERM and more Cheat Sheet Data Structures and Algorithms in PDF only on Docsity! | la, Binary Search tree Bs) : 2 OST is a node -basel binary cke tee. cata slrucluaw whith bos the | | | | | | i Fol loan) \y po Vey: \ * The left suvtrec of @ peel contains only Hodes with lays lesser tan The pade’s key, ‘ us - KL svbPee_of a pode contains only noclos wrth bees gproceloy thew, the necte's lou. ‘ ‘ 6 . v 8 The elf and viQhl subbue each must ally og OS, | am | Or 7 Sh ©) x i @ 1 How 40 _seavch 9 oinarg Yuen — j 4 Start atl tht oot / a - (ar Securch the tee fovel by wel, gnltl you find the clement Yyoo_ano ||, sravening, for er you Foach altat. Pub Nope athe || & Searching inthis (5 rat better than linked LL as it tokts OCiogn), a Smallest clement at loft mest efomint. —_]L A Longest Clima nt ot not Sts Ate ea Ta ba a erin se Se Se Mow’ If * Stop ett tho_roo mas a Se ||. * Compary te volt of P tho. ‘ftw youu any seanchiing. hr fth || _4ho valeo stored at the rook $$ + OF tho value ord _eqeal , thon ttn founcl + » offanaxSe, if it_is_a lal nod, thon not fond. + TF it is lnc thon the vaio Gloted! of the root pan seam the eft subtree. i % OF itis opucitin than the bo vated ) etored “at te reat, thon _ e_ _— Search tho rficnt fubtrco, i + Rect sttps 9-6 for tx root. of ta see Chosen In the Pyevious cep Y orf.» ——__—— a “+ Fonction RETMEVETEM + a | What is the size of tie proslom~ Se - No.of nodis in tw Tease an ontinging ees eee) fa -Whatis— the hase case G)? _ a | _ fy whon the uy 1S found. oe | itn troteee is. empty Chat, wos not fours) __& What t the qoninal_ cage? 5 — S€arch in ths bétor ng sub Bites 5% Rulriove + 1B. us 2 js a Gupart 13 with!2: —__—— &mparw uwith 20: Compang 18 with 18 Choose right subir Cheese bef subbur _ Found}; Cuvant — wee oe mS Z Somat Sid Nie oR ara So ew Eee Con ‘ o : ‘Does the orcas of ns. Aum ne tree mrailtn? ) DA :PREACEG {8 —_ Oe - a - —— = bi brat BADCGFE LC) Enput : ABCD EEG. tree = @ ee fp Ye iy N. —_—_ Ls Yes | the ovdtr of ering ckmnts matters. a Code : : _ 7 Binowy Saath — Mee #inclede <stdibeh> | Binclude <sidlibeh> l struct _nodef int bag; - - —struet nado * loft? struct_nede * right, p ens struct _node * neaNocke Cit i) EE struct nado “tmp = (struct nedt *) malloc (siechiatract ald) 5 tt temp—> lea = Frm} TIMP > RES NUN return dps NULL? i veturn tmp j a void inordorCstruct nodg * rooE) (a FP Croot 5 = NUL £m (hordor-Croot->—lept)-2 $$$ printf ( eed >t tet ala); Ss inorder Crpot -» pe ; { ol J ee ingort (lruct nel * nod, int int it Prods = =NOH) __FEVEN nwNodMthap » tay <node > key) “Ue. = insert Cnode ot yo else Bele ais right “zinsert (redo > rig, kay) returns gq Struct node * minValeoNode (stud node “node f Struct node *cussunt = Noda,” Ty ico L=NuI tlie (omant 1 cwrant> WE T= NIE. a, — return [ss STS ite le Sitters rape el "tS CU PUNE > (OE, return frie return queunk? —_ : eat Ip a - || struck node “delely Nodo(str uct node *root, “int pt a JL fh Groot == WL) petumn_roote ih ches < Toot >kay) — ——— root-—>-eht— ole Node Cook Lope, lop Se Oise if tees —> root kee )— root rig Mt-= ciliedacooe- > i wy) alse ¢ if Creoto tet =Nuof “struct nedy “temp = reot ange $+ —Freecreot}3-— — — — return tmp: 4 Lad else Pret right == Nuit net struct node + tymp = foot > belt; free Croot); return tmp; struck ede tomp-=nuinVallutNade- Croat >-r'g hb); Yoot > key = arp key s root > (ignt= dululaivode (root: right, ttyr)-> key)s 4 yeturn root; eo + Replace thu data “of ae “rede to in elec with ede deta oe + delet re 2 decasser’s. dato. as _ dae No fe # Tnordin traversal. (LDQ will produce a sorlidl _ gta. in BST ae Cus) * Srordon Predacessor -» largest ve in lib subtree a || 4nordin Secessor Seals vole in. right subbup See — Re We. “replace thovilen predecessor ot Grover Sucensor | with the node with ttvo _chilcbwh oe cow-delaing. ee cer + a ee ee ee _ a = 1 L _ i 12 Companins Pinany seanch Dues _to Lislear Lists: Operation Viney Seonch hue CES ice IS itll @ OG) OG) OG) EsEmpty OC) Od) —O@ ae __ Retrievedizm _ Clog.) O(LoqNN) OCNS |, Grsert Stim OCwogN) OOD ____O@)__ Delete ftom OC04 Ny OM) ON) eLtnkad Lest? Pres = insert, dele ns ~ search ee ee . Array > fros =Seorch _ — — | + Binary yur 970s = insort cold — {i ON | «BST» Prox~ msert, delet , search Cons — Stoych | ort ~=-Ocny cm St =o Search — Average = OCleg,1) Ewha Skaused- BSP Chapln-?27 AVL Trees Balenced Bincay search Aree CAV. Arte) + Ralonee Factor = Hight “ae Subbiar) = edgy (Pig - svbbud) —t ic, © th Or li ted ety ©, @ —— helmed Gage) struct AVLNedlo £ - - 7 a a : _ 7 7 iL ot — —lint data; et be FI ih Me __|| ie nfo, _ —— Stud AVLNode” (ef tp —} Etude A Ned igs ee nee cE | a int tat Cotrack AVENode 3a P Te (== NULL) a i i return Oy ~vyetum n-3 = height —_— if ——— — ~ ~ - i ~~ get Balance CStroct Av Node “1n)f np lp mess NGL $$$ el RE returnO; oe a —— ——— rerum Cc hight (n>. left> = height. Castigh))F 2 $ eT ee i: iD RR- rotation ~ Single ett Rotition Mo: @,. Rigetod 2a Retati x C6 Tet siae _ @- RST 1 2(ug) + — 7 \ Le Newly Inserted | Struct _AVINCds* singleLeftRotation Cotruct AwNede” XP 1 gtruct AVLNedo *Y = a-rrighte | Struct AVL Neco * To = Y -e lefty oo 4H nt mid tet =a 3 a nee | a srs i = fo? — | retern yp | ame hee = rox. Creight Ge~ let) 3 height oe erighty De je Reger = _ Max Cheig hit yo) , heighet Gy-otight) 9, Jj chruct AVLNedo® eRstation Cstrodt AVE Node oc) f Ter left = singtektt Rotem Cae WF) return singleRightRotat (xc) a Pete whe ty) RL - Roterhon - x OQ, behild Cy) ©. aye Rota tt oe ‘ % f Rigne | ~~ i ast I \@ ‘ struct AVviNodo* Ri Rotetion (struct AVLNode” Df : &-r right = single Right Rotation (x right)? oe return—singleleft Rotel Cac).+— re cds | | | | | | | | | | | | | | | | | | ie Ensertion- _ —ot Struct AVLNode* insert Cetruct AVINGH@* root, int valu){ jf root == NULL ee —}—____allooat_menory for ‘nods | set. rede odie = = you sf root > bft = _ ee : ce return root; gor foot hoig ut = =f | ; a ees a value <reot » it > dat dh — root > bets insert (root af yale) ae root > night — | _ gm ~ insert (oot aright , valeg \ | root hugnt = EF moK Qght (reder 0") acgick Gan raha win bE GetBalerice (root)? 4 fo ket 1) otetion Pe Neb Ratan 9s seol ok ft Sobimevol A Cou tice treXld bF CB) = 4 Ceigt, 22 i = LR — Rotation __Choptir-3 M ult wor) Frees SUbbues - om key Avalus + me - J per Ney ae | * (nsort_x oe “AA a Ione fag Ade—ree=t = Lnsert 52 in aboes “rut _ Ey tel a rr « Eyer intrnol_pede. of Mau way secyich tre hes —__ sett 6 chile — a upto! M-1 “Hays MaMa a2 Ngaf 2 et ee ss &For a 1 Subbu te, 0.5 h chy el of a node, all. ago in Te ust be_ b/o ker ‘Gis, kt \ ees ee ken < key (4) < ke el ey k lydlaa> kos —— pe uoage ine forse seach + Ol L041) Worse — OCD OG) PETE vedecin _ es _ SP hte \* &a5 for ineriiory +m0 cong. same as Searcy + Onsertion Search , “Weleda. = OM). ee i | —Sotution—for—it—B—$- —Bdlencoel. M=way Search. bra so E ee, he Oren B- Gf ack, —» lft DE Lk | 4h0 node has _tewo childern =» right subbiue TE sess node has 9-childiens UO Racks a middly, sublig —£ a ky + right _subbiee ° Prserting~_Prserlion alanys dont at waf rode te Splitting oF node; P Cx a ig ehid i 52 pit FA pO EBA, 6 ® tp = = Sy ST A Ty pNe e S tehive e l eniealla 32 — Insert 39 32 ud U7 i - a ¢ alloy) a foe ee __Snvertid 42 _ fab, (voit) —_ ‘Greed 47 = _—— po fer [69 [90 a 99) * Debt 69 0 Replay jt with inorden_successer. =. [54] — el 135] yet eae a ninen No- of 4 veith —heigit = ~ gs ety [tte ttc ar Hey wt petty Er — os he eat ——— _ arch “t= Oe en) __ | —_ I qnvrt us ths nt ewe oe BTSs é —__faslisl 36 [45] , = : S\N + jefe jas}z2] mae — KEEN Ll siti a eS ——_——— Tr 1, Doltion in A Tree: OC!°9,")__ | | Brery-ne node should. cordeaio Bt ji a mm entldnen ——— tn ernie ondetlow ee _ | Deut 99 » cls Yodg tes) — ee ee | 2 mS ‘Delt BO: Uneterf loco check OFF sibling & vight siblings Right sibling rawr mere vel al ¢ po onalboay) So peli ir fron pig Stl from _pargnt_dewsn. me id 7 a panmen— se Troe] st ray F36Lus Eel uss Ee 422lio ficclus BS iby 21 _Chaptin- 9 Binony_teap Orating Systm SPAT Cshortist Remaining processing tine) = Data Bret for spRP= —_—_ 1 Unfinished jobs ot ang point of time se | ib we reed to maintoira tne remaining processing tim of | We nad to Find tha job with the sheetst SPRT ft Whon job finishes we should _rems yo 1 from oun —__ealkiction. : “Sy iv) Waren crow job arrives we neecl to add t te the cabochon, basic eperottions- nial Lat sere fray tae O57 7 mert C) ODF __ ON) odoe9N ) o find Min() a Ow) Oa) OCI69.v) i) remo NinC ) _ Nn) - - Oon) We wont- —_ _ Insert OGogN) fe ~ find OC) _ Priority Quy | Dew — O09) ah 4. Binary, Heap? | [Ce Ts binary Ve Crot_Bs7.) thet cctisfios tw Propenes. iy structural Property All Lugls excspt tock lovel cre ull £ (ase __tvell_is (ft-Filled.. Ccompltt_ Binary Bu) ee = compl Binary Tree i. Be il M tys ae than__or or equal. its chi Idecay Or _oveny nodes Grodin tnan_or equal to_its hula _ _ Qo mm G. @ a H— © _ _) Ce) _ @®oOo Min heap Max Hap ; chock Min) (Rect Max) + AEG, Representation | Max Hap) Vavergl will bec | (up & down) jt es Pace _yequivempnts. : I~ OE 9 9 3 _ Q bale {4} ula] sq | [ae A 2D we \ Pewnt nede= LO-) - © é e debt childs) ORE) Rigi duld = 2042 “Wclonoton = Struct Heap > f a > lat * arrays : — IME county No. of Clompnts mm Ab capacity : A Size of Heo? 1 heap type Max Min I - =. z | Crean a. beop- | Stet Heap Coat Cint epacitydé —___ hallecedy _a memory for heap P| ll set lop 2 count_=07 et nap > capacity = cepocity ’ ‘1 alloccts pitgrery Fox hee p-ariay 6S for te cePaciry ie | ———ye torn heap eas Ponent of Ned Rt Rarer Covuct Heap h, int PE IR (sco i t> h- cont) ren -1" eg ° veturn UDR; j HE chill oB right cid = wat Wltchid (DE eon ot fat; int vightchid¢ ~*~) { yeturn TC41} Oo G_O_ 4 oe theo a a | _ _____]@3) 5ul_eshalaef-—f Jf 9 | jsulaclusfo7! TT T | Oo. 23 | 5 67 — | ot 23 45 67 Void insert Cstpack Heap *h, int datat — — —if.Ch-+ cot wapeny et po —____ Pisize hea pCndz po a jp inte Sh COuMpe po herarragt’ = ded — —_h-comttt 3 ee while Ci>=0 84 hs arraylt7 > > bre orray Parenti JL | ___ —}--——swap Chhes re arayle] , bh-- arPc array) > poe t= Pom chide a An elimi ig aloes Aulited from ths. noe at fio hoap)-So, clin, an __ elonent from the hoop dong into Follewing J St Stops ® Roplace to Yode nede's valtg with the last node's valug so that tho tue is stil a complte binany: Bee i) Dele tne lest vieds WD Percolat Se Airst rst cenit. ~<————--- he e Ye ony ook peti oy ew U5 — eS 8 wD i eee od 2) ge ae a jak Dalett Max Crecp hf i mt dat eka _ ct | if Ch Count ==Q) Se | return 1 ee | | data = h= carraylods | a arraylo] = ho carra gnc yy ee i hh? coont=—j tt | fercolati Dean (ho SS _ - ie | return Dotas TCO HI adh we us t- - oe nelomonk —» Have _to_putt Hye elmauts jn cs onder. reat 0 heap a op erect ty till heap beeos empty = \| i ——fastiad_cse_eill bo On Jo. Ln Place Sort ee = a | (iaapeloTn ] “lat in | heap spo) geet Car [ig ast Hao . iy Unlforaify - Bnd = heey wash function of. nde = hy) oo A a Mapping the keys 40 appropri, locations Cindicis) in a hash table is cablecl as poshing. (ca) rCalision.+ whan to oF more lays map % He seme memory locotieny, ° WE Can cheese best “Hosh funtion. ee But it > te Birthday Pomadoy. * Hash function is the mochonediceob fornula which whan _ applied ona hey, produces an intigen euch ean be vsecl _ ais an Idee dor the Mey in Heshtable. Main aim > Flemtits shoud be rondenly 4 oniformly distributd.. Propertits of crcod Hash funchont |} Loco Cost. / a iy Dotarminism — Cunmated hosh_ value should _bo the sang. of fey whineven - cofcalat it. Bo Different Hash fonctions :— 1) Division Methad - Mis sizeof hash table hod = © mod M Don’t choo s- M29" or close to it Choos? ¥- MPa No. 3 Grew > he even oC» oddl => hod oad M<9? -_ _ =! eg haga3u> 1994 %97 =70 NC935) = \999%97 = 7) HG Potential’ Drowback—P Cconsecut! ve koalas Coe ipa ~to-aonsecutruehash-vadtas —
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved