0% found this document useful (0 votes)
45 views212 pages

DS Part1 Merged Compressed

Uploaded by

shuklavinay2140
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)
45 views212 pages

DS Part1 Merged Compressed

Uploaded by

shuklavinay2140
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/ 212
Ques) What is Data ? Ans) Data tsa collection of tnformetion , but ft is fna yaw fad when data ts proceed tt becomes an information s proceed data fs catted information. x Data tS a numeuical, character, symbols ov any othen Rind of infov mation - x pata is a ptuwtat form and singulax form. * Genexatty a programming language supports @ Set Of built clataty pe and atlow the user to define new type , those axe catted user defined dato type- @ Built-In Datatupe suchas integer »ChaxacteH , float, double integer, etc. which ate defined by cae tang wage itself - - euser-destned Data Using theset of built-in -aakeepe used can define hfs own datatype- “OY eg» - 3 Typedef Struct Student” : chat Student Name ; int Rou.No; AR heen etesec des — ~~ # data Object — ata objeed & a woum that wefes tO. set Of element [data such a set may b¢ for 69 a consider a stt of student computer scfener and Enginecving is a finite ser, whereas set Of MAtULAl numbers é& an dying fy RIML am year 0 a year of @ pata structuxe data struct fs a way of drgainsing dota by ustng mathémicat o¥ tegicas con capt j oR, jogicar and mathemartel metnod of storing and otgor’yg) dara ina, paxtiowlax wey trad it can be suequirtcrent for designing and mainteing fambiementing Of augawnith « Foreg: Aray, Liked Usb stack qyreuc OY gva ph ‘pate struce a. : OR r x In compursdenet, eaara, StrucliHe a claborganizatin management aft ctorape format that enables. effi Cen pxeess c.ceas and meditation « Two way of Lodking af data Srructune » Mathemasical |Logicts | Ris treck mocks for 5 A si Implementation feeding] Psegramming Paobleme +08 compiles computer trraphite @ Soon + Dota rear ea Thiplementazion coguing Basic Terminology mone ane vafous terminology in data struct: para »pata frems group ftem wrecoys ion of vtaw facr ané siguixe OR = Palay axe values OR - Data aue set oF values For €gt You Name = AyUsh Shasima Your Age 13 Youx AKTL Rollo = 22036T1S 30018 Youn Branch -¢S€CAIML) Yous fathucs Name = mr shiy Dayal Shavma. ed fato. Again Non- primitive data structune axe catego apataitem: A data item a at ane divided f two type avaroup tem pare Trem Ih u 1 Lineaw date structame eg FH ay snentna « Cayuar: Shes ayNon- Lintas Gora strudtune: ’ pata tten Data Structute Non- Primitive ddta Structume ata Structuxe —-Nen-Lineax id Record uyRecord- ec on™ An entity & something that hes propenties for eg aos a Float stack (fvray, Linked Lis) S-No- | aok est ae] ila - pouble Queue {Arvay: Linked Li 1b fast | cot] 22] na" = z + Quimitive Data structusie - 2. | xe | 0002 co a] 21 |e Data stu: Note: Het ent ty is table = collection of wiecord of one type & catted sile- @pfittd-single dementany unit representing atuitbus of an shucwu not dirty apeiott upon the machine entity. ts called Fietd ‘information- data with attyibures & ecbed information: on. Meanthgful data i called information. | ctassification oF Data eLineay Data shuctuste- Dard structune Whose Clement oe sored th poouideutan evelor that i , data eanbe proceed ane by one seqiune Linea DS fneladi the foltctoing typeof .s? ov egy- AYYay Ll o Non Linea Dove Shyrectuerte= ‘9 Fiementasiy Dara Organis: structunc/Type of Data shructuxe, dove structune ake TWO types? en, tb Red List, Slack, Quene Data smiucture whese aementart ren iy catlid Non-linear dara oy erored in postnicetter ing’ type of Data structese: gtyuch heads Mm for €g: Tite and graph. fneax and Non @offfeunc Bl tinean Data siyuetLure con Ds. 1AWHe that solves Avon Linea dove Srructune Aprocess or a set of suits to fe followed in Caleutarion ey cthur Th this data shu qliments ae evgc much as aosecay, NR queue ntineas ps ingle tobe! fs invetued: For eq: @ryay COTO stack a) Itiseasy te andarais ina seque implement because z ‘ 4) Data euments can be traversed ina single yuh onty 5) memory & notuiiised fn an efficient ary e) Apptication of aM DS Ot mainly in applicatten dmacpmat wepesoftwar: is BS y elaka és cr qanise J sequuonet prchlim sewing operation wspecicuuy by a computer « An algorithm fe a finite set of tnstvuctionsjor poxforming o patio task te called algovitym. she inepuuetions owt noining but it isa stazment fn simple In pon-tinecer DS mutitebetse axe involved engtish tangucge- For eq: Tee a “ for eg: ugaite an aigasiiinm to add two numbers entuied by unew - OR Toke a veuy simp ecampl of an algasiithm which adds two nurnbou and stores the susutt in third vasiablee . Stepi: STRRT Graph = « - Step2? Declave vaxiiabu num, nuna2 and sum 1 Read values num And nim? ‘ : Add numt and num2 and assign tu vusuit to sum. (gume numt + num2) Display sum (Pint) Flow chart Declare Uaciable mum num? and sum WOT Ts tHe to Fraplement JAue to sequunting pryobuim. )Pota euments cannel be yavexsed Ina singte vin ony. srmemory whitization is dry W dvay - 4) Bpptication af Wem -Lnten Displey sum 10g rem ttineludecsidic +> Pinel gconio-h> veid main { fot uml, num? sui printf ( scanf(" 2d ted & sums numiinum>; prinyeerhe sam i getch 0; } ave) chaxactexistic ef Algorithm There axe five types chastactoristics of an algorithm. 1) Inpus 2) Output 3) Unambiguous 4) Ffniteness 5) Effectivensss » Input —1n an algeyith m can have eo or move well defined inputs. 2) DULTpUr- An algerithm must genet at lecat one owpus 3) Unambigueur—gam invrudion must be clos- foreg: Read 0; i Read b; ; int A; Fini - eu i init * Finiteness - every algorithm Must have finiti numbex of steps » ond wey step Lithin thas algorithm must tam sinite ameunn DY time for execution « perform thar tak for which do t thal cugovithms means give Ourpur Lach ératyuetions of an algorithm must alse be feasibu rn, Eificienuy of an algorithm eney of an augortthm ean be divédtd hy measuring tne han algeritnm 4 9 MEASUAL the pEtformmanc ef on algorithm by computing © \wojacrors. prmountof time otequived by algorithm fo erccute tis alse Rrown as time comptexity) AMOUNT of storage Tta.d- by an algorithm - Fis also Rnowh Os spaci complexity) time complexity. Time compuxity & te amount of time tater toy th. puoganm for wexeeurion LL to meaawwe the tine compurxity in the texm of AU meascoie te tine eomptadity using eney Of. 0 program & measured by cunt inthe algoritim inovden to eouUnt ee No-o} For 4g? Considix following pice ¢ coc for obtaining the frequiny count void mai tai dies a= 10: b= 20 c20tb; e) code Frequency count Totat 4 (constant) Frequency count. int Sum[intaltol int nj] int i, sum:o, Joy tt-0; fen; ft) sum=sumt alil; I vretwaAn sum; code Frequuncy eount sum=0 for (to, tens tt) J nt) Time complexity = O(n) sum-sum + atid; n yetusin sum 1 T(n) an43 Time complexity = Ol1) i consides the following ptect of code for obtaining the ZPRPRPRPAAA RR ARH &@B MB O&O Bats ee ee Be ee Bannenhmnnoie a Space Complexity *The Space complexity can be defined as amount of memory HeqQuuyed by an culgortthm to stun. +To compute the gpact complexity we ure two factors — constant and instance chostactestistic Note: It is the memory orequured by an algostithm 10 compute a program and produc ourput: hey FO any algorithm, memory Negld. for following pusipose PS 1) To stove program instructions em stove constant values 8) To stove Vattiabu ValLics uj To stove ayuiay aize c Band for fern othe factors tiRe function eal jumping statement and soon: + Tnexe axe two type of components that contyibures the Spaw complexity 1) Fixed Pastt 2) Vastiabls paxt eg) mesg 1) Fixed Pout- + instruction . vaxtablut . cyutay size D . spact for constant €x) considt the Joltowing plecr of code for obtaining the fixed past spac complexity « function add (nt, n2) { sum= nit hd, yetuyn sum; j MELLEL UCOLE - Anaty! nl = 4 byte n sum (Puxitlany eM memovy) constant ow Numbot of epaes oTisusevaan No- of inputs % a Pea ne a @ whose size depend «pon the problem instant being solved . The control staternent suchas [YoY twop, do Loop, While loop. choitedso#)axe used tosolue such fnstancs: for eg: considan the following of plgorfinm 4o compute the spact compluxity - Function sumOfNumbex Cast] 5 { sum =0} gor tiz0 to N) { gum =sum4 wut Ctl; 4 printf (sum) Anatysia : Number of Spacis Ly i 0 S72 Seales Seaman No: of inputs oie, the span complexity ofgéven atgorithw progvam can be denoted in the texm of Oln) Asymptotic Notation: 77°? +To chaos nm , we Need to check efficheney of each hm. The eictency ean be meastutid by computing time iy ef each algoviinm. Asymptotic notation Way to stepresent the dime complexity comel © shovthand using fsympt Notation, we can give time complexity as “fastest possibu" , “slowest possible”, " Avetage possible” svoxious notatfon such ox oneal t. 8ig-h Notation (Densted by‘O") , west case complexity, 2. Omega Notation (denoted 1), best cose compl tnenoted 3. Theta Notati nat no denote some any ¢ & 6 greasen than 0 ze). ite we can 9 Fin) a cin) No-oF steps No-of Steps ceate n No: of fnpus case [Tight Bound [8): a. The theta notation metned the wunning Hme fs berveen AE No-of inputs Definitionatet Fin} and gin) . two non-negative juncsion- tet ‘ng and constant Cae tivo integens such that nod andnis greater no (rane) so weean write with the $0 wecan say thar - 3. Theta_N tation | Aver denoted by 6+ By this tows Ind And Upper ‘pound: iqition: o-Let Fin) and gtny axe tent constant ¢1and Co such that we © non negative {unchig some values of in} ane two posi h thad €>0 bSimflasly constant 'C* het of dfagrom = Fin) < Cx Fin) is bigoh of gin) eoxgin) fn) ipl sorne constant ¢ lem other words Ftn) c gin) + gin) is ™ 2.0m fon} Gest case tower Bound (8) :0-9mega. notation % fs wed fo skepresent the (010 bound aeneres by 2 of the algovtthm's stunning sme es we con dmote shovtest mount of #Tme No-of steps busing net token by algovithm = IntS and gin)=%- Inen wehave t prove fy Finds ex g(n) F(n)2 cxgin) ) Cixgtn) & Fin) & Coxgtn) Fin) © tx gin) 2045 N29 False cox fg Case tight 6 Cregime FL) £Ca* gin) L£antse 3n For Best case /Lower Bound: ond rrode-off fs basicaly tmemory utiiization) can be ach iceney (performana efficiency) con be achieved at the cost of memory. Fox example: ime eun|tomptie P00 Complexity TO sity fun) ton 1 Progyom 1 } 2KB Program) \4KB. Time oa Ug Va comptsity ‘eral Bas [Program 2] aKe ficcording to time — Memeyy atiocation inc: CNot in AKTUsytiabus) of memory atiecation fn ¢ memory Piocation ( Run time 1. Static Memory Allocation: ane a Memoyy atiocased dusting compile ime cand static memory memory allocaud is fixed and cannot b dtentaned diving wun time For example: smamory & auocated at compiie time ond it is fixed, nobedy can enangt expignation: duments- ftthough “For camp hore, you aus, which co A exe that the compile time -The py ee grommen has fixed the size oF decx oh memory for on aimay during comp € at the time of deckvation. size tase ov dtentane te size of the actay a tne valtes atoved by me user fn me aseray of sun time t less sive specified ten MOL wll be wastage of memory 0 thon for exempb: int mat { int el: {1123 } ¢ values stored by the wer {9 the axxay at sun tine & how to work pointer then study Pointex + "1 .: inter is nothing -but it is @ vaxioblL (OMPOXLME ) addocess © symbols used fo pointer: © & campetcond) of opexavoy k) - value at addyess operator i shat stoves thea dress of otnes vaxdable which 0 memory fov exampl > epiiae? | seer ner 2 en chor, [emery oh a fxamipt: bint 0-5; ate] aml = &a= find the addsess of ‘ya ® u'a ie. addusas fs tooo — C_I Lore; = x pty; — oe oa ppose phe pin", pty): nd int, * ptr); ~ Final o[P: 600 NOTE: Size of pointer is eqytal to B byte: (su bits) 8 bits axe rbyte 8 byte 6u bit ofl woes ~ Suppese » (ove mmo — SUP pOSe ma); —— 20 u", b); 4" ,#b); —>dood ue bb); —> 2000 Dynamic Memory Allocation oA otefers to allocating the memory to the variable at stun time 40 that the éize of the varfabu can be dat Uses FOUN funtion from — 1000 a Caltoe () geuous allocation 3. Realloc 0 ~ Re-atlocarion Me Free 0) tion of RAm heopmemory pa a memory allocation musenves a block Of memory of specified no-of bytes [bits tdoes not f block of memory auocation f hen it vent a null pointer Syntax: ty = [Datatype #) Maltoc (nx clement size) i Pe example: stove vam equ fn'the main memory with the hetp of mattoc- RAM ae 20 byte pty = int « Mattoc (5% 4)5 Note: Mattoc junction only used for smatt data aaa is contigtious aliocation setues no. of blocks fn memory 1H oietwins a Udid pointer For example: stove & tnteqex with the help of cattoc: int xcattoc (6) 4) 5 ptrs 2obytes eM, pty fof atineared mauioe and talioc fi syoax: = -——~ Atew sito _ [reattoc tpt size) 3. Reanoe ts wbIr changes the Note: 8 FS used for changing tesize of prev hen davige oy smal size ly allocated memo tel): It fs used for victeasing tne space allocated by dynamic memory ativcation sy cet Free variable name)| Ques) write the differena between maltoe and calloc matioc alloc 0) Tit is memovy altecation 1 His contiguous allocation: a. rhe syntax of mattoc is lathe syntax of calloc() is ptr={oatatype x) matioc (novof elements) ptr= (Datatype x) CallOc (No-of ~ size of tuments) | eternents, size of elument ); a ptiocaits continuous single block of memory is altocased memoyy and each F : ral fn specified sizein parameter. [@Ha! Size locates multiple biock oF lock, enntain, le. pttocared memory tocation ast]. piiocated memory Locations ave not initialised. specialised: s.Thene is noinitiagization then [s. there Is int aime efficdienyy is more than efficiency than malloc entioe fundion- J (2 moi b Abstyacl Datatype (ADT) = ADI ane entities that are defi but do not have tmptementation details fon of data and opexations int atsl; 2 Case SHomogenous Eument| Same dato. type Datatype (2210150) a) chat datatype jafekepey e) = = 2) float data type Bes) ke number ‘ni? of a ecument & catted lengthlsize of the auotay: oxampit: fn) ATI. the tenghh of he arOL0y tan be obtained as — . size = UB -LB th fete, 8 = Upper Bound LB = Lower Bound For exampu: tnt RIN]; wheote capital N See ae T maximum afeeg me wor] tt Corn Lower ae rf OnRoS Baan 6 Type of _Arvay There cote mainty 3 types 1. one dim Nal oyvicyy a, Two dimensior 3, Mulkidii 1) one dimensfonal_Brrvay : An artay thot con be ouepresented by only one ciimension such as stow major coloumn major Yepyestntation.and that ion and of same type of data-items~ & catted Bh e clement of the amslay ane stoved viespectively fh auccessive memory tocation By'N' NuMbex of daments is cattrd size Of AM akmay- The elemenr. of an-cxviay ‘AY May be denoted in Clanguage as ~ Atel A(t) afajafay -~- ----- AEN Find the a sof Ya cument ne adlreR Net css cet bth ERED tpt ~ one dimensional assay win try ements array fn seqpeenctially memoyy tocation rte sytem rete not ReeP stored AYER’ of me adeburs oj Reep Naeck of the address of first elument onty. mer is card pare adasars of arorcuy very euoment of 1A) bu De For tramps inr ALI; int ALi = a Ee {rey 207 307 407 50 0 aoe se tees Addsuss of mh eument = Base addvters + at ete Indx nox size- Find tne : p23, 0 ACs) ,@) ALI] ,@ Alero] SS @ ale) = 2004 24 + 08 @® Afs]+ roorseh 2 200420 70 ® Ala) = 200474 200428 »us @® attol = 200 +o#4 200 Mo = Yor =: memory fannehhe found , © @ B megs 6 Modification © Traveaing ATU fn_one dimensional is the process of visiting enisting are of the array array ct ly once each element of He 4 oe Bo ‘tavhing from tre fltat element upto the last © element c pleorithm Supt: START step2i T<-L8 Step3: for T— 1B to UB Stepe: Oprine T Steps = Sto? @ Insertion in ove — dimensional avvey > Te insert the » clement in the following different position ave 1s ¢ dhe avray Om te Gaae os of the | Gray @ae the gen @m we @ Fesertimn ot the tnd of He one Algovithn Stepi— Stor step2— xe ves max Size-t y then write array overflow ond Step3— Read Deta supe — uae ustt acue] <— DATA Steps Stops Explain : > Read vate < 65 ua = 5H vB = 6 ACE] = 65 Ensert clement #9 “un = Max Size-I 6-49 Reod Data < 72 va = 6+! vB =? A(?] = 70 Step 3 Znsevt element 75 uBR 2 Max Size —1 Read data = F ug = #41 ve =8 atel=+% srep 4 z Insert ment go ud = Max size-| e238 Read Para gp up aH v6.9 B{S) =¢0 Step © fe cConsided an aHxay of size 1 Gwotenttg mou anes Ingo oten y " 7 cont a duments in this May + 10, 20, 25 3013S. Insext dim Boe ee ~Y -tnt 65 at the begining of the axxay 9:3 @yray i ovengtow - fe Ls [20] as| a0] 25) [LL a)Inseufon at the be i “ Cn ae a a oC aE A) 2 po _ beginning of tne arn il Algorithm :~ ‘te i” KOK - Us = mox size -I StepL: START |memory Us to fatse step 2s 1} UB: MAXBRE-I then we write array, is overtte go to next step ane sto i gtep3. Read Dato P Read dato (pata is 65) Now srepu: Ko UB set UBS K @ Check K>LB step 5= Repeat stpS white x76 4>0 True Stepe: ALKA] — ALK 80 tw OKI Ke Kol asl <— ga StepT: ALLA] < pata wfz0Jas] so] [as] [] | | steps Sroe- 0 ae PS ears 1 & K wo] 20] 0] wf sof | ] | | oe oo =, Now set K* K-1 (4-1) a < Rat wv step? ; a UB = moxhize-1 35] to] 20] sofxo[ so] | et site Tin. Soe Ree go to next step Raad dca (65) Now BRL WOE CHER KOLB 820 Tru c Se acKyi3 © ACMI ae de gee OF the given position Locatior a tep arf UB y size) write overflow a ae ep arene Q ntion where fr on Ww ‘ PS: Ke OB a Kel ' | i 1 Pal felobal Tea cider on xutaay s m Med cme ant 10 ia ‘ Imtn¢ 5 at tocove es ll tsts—“—CS step ae Now cheer 3 o 76 step@: stor E Check “peletion in one dimensional array - K > toc Jn one dimmens snoring ecHonmennee ' 322 (True) and insertion is possible at ony ALK] — ALK] jhe avray such as ~ BE 40 j the asvtay Now or a from the veginning of the autay et ‘i f ‘ ion/ Koo wih p-specitic. | 1 ' Note: -pejore deltting the cement , first we nave to eneck te oLeTeshel Teal cof! 1] ae 4 ff No (N= UB-LBtL) , then anxay a MSS C7 8 . step@: = Now check, neend of the atay+ Reet algorithm Q22 (Tw) (gor nny atid!) 4 ACKI Step 1: START PES aa step 2: Tf RES! then Write undeefiow’and step step: ALve] — Nutt step: UB — UB-\ Step 5: STOP i) from the beg Algovithm step 1: SIRT gtep 2: Repeat Steps Hil K pdatuss of coturn major (-25430)+ @t(65450)) 5] NS J _/B-D Memory Representatior ® Row major ¥ @ coiuern major © Row Major Repyesentation += Now ation > F matics xno of Hous KAS of columns jot fon oeample = au ia onal assay or 30 Atay stepresentation in Yow for € language impiementatian addess of 30 Away | Multidimensional: end Latta) Lat es) of the anHay Quis We HAVE AN awtaY ACET, ~des, 15]-the away stored iA tne memory if HOW Major suprerentation £ach eument squires tritne man memory $F 6A b Find the agdseuss of 4k Multidimensional /3-D Memory Bepresentato & e two * ee OH types eran @ Row major vepresen ® column majov wepresentation © Row Major Representation t- Now in 1-D sepresentation ~ Total NO: of elements = No-of matrids XNO- Of HOLWS KNO of columns Eon eannple int CeI(s3{43; Total no-of elements = 2x3x4 = 94 “| TT] L | | oe presema > CEUlld ddd ddd ddd _ Nott: Multidimensional aswiay oy 3B AHaY major b& possible for C language implementation q addxess OF 30 Muay [muttidimensional cusiay: t tees $+ Formula _for findin 3 y where, , : Ki Ka, Ka= Find the location OF Matrices £),€2,83 = 1t(s, effective (ndex tile,t3 > length of the austay w = size of each eument.of tne AHHAY eA = Bare addruss Quis We have an away ACEI, —4:3, {:5]-The autay stored in the memory in sow mayor Supresentation.fach ement suquure 4 bytes in tne main memory $F GAH L000- Find the addy of eument ALY,-2,4] TEUCCOCLEe et , 2) column, major Representation of rault frevay = for ee: int (20¢29¢0 ova tanned Loe ALY, -2,UI = 1000 4 4 [Cx 842) #5461 : ole fi tooo 44 +6) 1 1S = lopod suy 2 19 x n Quer) we have an aviay AL-1:8,-4:2, 5:11] the attay ds stored Tr a Memory vow Majer supvexntation ond cach sentence ements oh ee require 2 bytes and BA Is 1000 + Find theaddvesser of ALS, 1,8) 0 [20] a] 22 | 23 fein) gA=1000, W=2 i fae ese KeS. Kok, Ks>@ 2| 28 | 29] se | ar Ul) 2-95 ta2F . 5 f2:3 , 3:3 :. = a's ts ]2a]is [ar WetACss-1@)) = tos IP Lexr+3)x 743] © 20 31 22 35) = typo + 2ft4s)143] Adddus coronation for mubi- dimensional Arrays Loc (AL Ku Ke ital) = BA + W[LE3x Lot Exel ter) Gus we have anc TEMEMOYY KMR ec memory and bare adders & afa-2ay. s] ine cwetay stoved fn yes. fivane mai Bus of Lement m) HEM» Kee-2 o KaeY 8A 1000 wey Ct 28 Las €irB €2.2 €3-3 Loe (ALU H2,4I) = 10004 Y[L3xe12) #743) toood UC 1824.3] = 1900 + 1H up Ge) Quy) we nave onaxay ALI:6,~4:2/5:11] the mtoray stored fn etow major yepresentation and each euments requives 2 bytes’ and base add*ss i 1000 ~ Find the adds of ALS ie] » goin Kies Keen fa-& BR; l000 wee urto w-t L3+7 € +6 Es=3 €3:2 toc (ALS)-1783) ="to0o+ 2E (Sx 143% 10463 « loo +2[ 20046) = Joho +.U92 ~ 1492 £ oye aa Matrix 1 type of matnix in which most of the eument/ Ty ca ane 2010 OR 7 a lor of eument from a maurtx have value ZX then iis unas sparse matrix many uement axe 2010 + PUD ELUNMEN} CAE ZOHO: for example: 2,5 40088 0 5 2.00 UXd Spaxse Matrix 0:0 eOmna 1,0) Oe Qo uo base m 689! et 10 1 0 WW ror otedualng memory spact- for XAMpu: Considine a LooxIOD madrix have S non soto element por LOW Men tu Non zeto psLentage oF maDAx can be calemtand as ~ To oupracnt 957- memory, By only Sy qu used and We save Representation of Sparse Matrix: Tate GUL TWO types 2 Prray Representation [Tripler Repraen tation. {sored onty non-zo10 eument) a) cinked tist Representation 1 ANaY Representation | Triplet Representation th the qwroy otepyesentation of a spevise matrix only the non 3e10 elements que stored so that stovage spac canbe vieducid ach non-zuw0 element in the sparse matrix can be vieprestnted aa! TRow, column, values) that is calld Triplet Representation. Foyerampu: consid the following spaxse matrix oF UxY ct Ce C3 ml @ooe Bl 6 Ooo el] > OO o Ay 0 °®o Now wie use vow column and value wepresentation Row vatues 2 column ° 1 L ip q Q a 6 THY» Linked List fepresentation: mast of size 5X6 VOW" and GS tist for column Foy ot men tnefr woud be five ts tov five Spats matrA Sxe ae eee Blo Of OO 7 Qjo 3 0 © 0 O asfo 0 2 00 0 gyulo 0 0 Oe S | an Cela t+ (kk fsa 2fi fal v00e 2000 3000 4900 ufels | al2 [21 k Too ae pitnt FOYMs of. Sparse Massie Toiose vastious ¢yper n ) iagonat masrix ‘diagonal mewHix > a) upper Tridiagonat moar fe) Lower Tidiagonad matrix matvix, which is @lso asqyiane matrix + Thete ate — when the non-zero elements ass sored on the 1 mentsitx, Oo 6, 2000 ° )Tafogonat Matrix: 1m his, non-2o%o element locid © keene. | q diagonal or placid on below or above the Leading aiagona! T InRed Ns for example: Linked hist is an example of Dynamic Dato Structuxe, they © RbOVE Widfagona! Manix @ Bede diagonal masz can be grow and shvink duxting eetuusion Of Mme program. a Memory fs dliocated as pet you programmer cored. Instntion @ 0500 do 06 and efficient o04%0 SC) nodes where each nove has two fields boo 2 o yoo Data field and linked Fi 7 000 0 oo 20 Tne pata Feld stoves actual pfees of information and js eyed tapoint fo next node prowesr Tridaganad maryix: wi o gone) Matrix: wheste the non-zeno clument ce Basteaty tink field 1 nothing but addvess of next node only: piaad belowthe leading diagonal is cailed tower triadigonal For exon ‘matyx examny Structute of node ato Field a o re rants <> {jore! Representation of Linked List (Basic, Method): {Linked List (Basic, Manod? cine ere t tinned ast consist of suits of data stvactune-they are nok cysived to be stoved in contiguous memory tecations exarnps br Lippe Tridfagand) Matrix: In° this, me non-zeHo elements oxe ot of integer VAIL 10)20)-Bd«49, SO plaad above tha leading diagonal: ere sa S005} {20 [eno] a0] wove} fo [sean] feo] Non o a) 2000 Bo00 Yo0o S000 0 oN6 4 ing Feld of the Last nods consist of NUL whi oo. XG Ree eet xs {5 meintained depending on the steqgiivemen is categorised into vartious types + tans Pie: info +vamieh > PCR) singly tinked Uist J Kineay Linked List? ean rinked Firat pastt cont +P ( stepys ce ='N? go # step @ otheswise eo ae® Step 5: Repeat step © and @ eahile ch=='¥* Steps | Checks A vallabibity Temp = (State necle) mallee (Size of (Stat node) Read ingo Ctemp) Link, (PRES Terp PrRS' Temp | Giep?: Repectt: choice C¥/N) lepd > Link (PTR) 4% NOLL Steet: SOP eath nods & aft in information of thi second part contain meadduss of the next Mods in the tit fe each noet has singte pointer ro last nodes ease o Nutt poi nodes fh the singly inked tist Logical Representation of singty tinked ust elo} 8} 8a) 1600 2000 ‘Bove ws0o 5000 Ag, thar thuu axe no Gasic Operations” of singly Linked tist voreating tinned ust a) Traversing = AKTU 3) Insertion : 4) deletion 2) Toawessing_Of singty. Linked List: 5) Sorting algovithoms 8) seaxching step 1: START cope asye UNC Se step hen waite underflow and stop ® merging e] i step3: Set PTR <— FIRST g) Rwsaing stepu: os Siep@ and@® while PTR |= NULL seecution = = 5 steps: Potint INFOCPIR) Algorithm + Creare asingly Winked uit for USO a adie Steps: PIR= LINK (PTR), step 1: START Step: stoP srep2: Ceheck for availa yl | . PTR = (Struct node) Malloc (Stooge Of (Struct neds )) Tf PIRES: NULL then Write “QUEtfow" and stop. giep 3: Read InfotPIR) Heel} ee te Sg) instation can fe elk Stepys Ling (PTR) <— FIRST Bun Bosse PTR <— FIRST ae BIg Se GS EHeS) }) insoition at the beg stept: START gientlasty we can insect S1101'5 * a) inseation at the end of theuinred cist? shep2: If Fivst== NUL the write Undyfiow and stop TART step! y FIRST ==NULL then write undeeflow-and stop step3: (ener for availaditity] (PTR= Avail) PTR = (struct nddex) maltog ( Stovage of 1 PIR== NUL srepa seeps {eheen for avaitabitity] pins (Struct node x) malloc {struct nods)) srepy: Read InfolPTR) steps: tink (re) — Fivst PIRG FIRST ar step Read Infoc PTR) tor (cpr) == MULL step CeTR) & NULL step ior BU 3) Insertion at given 10: agiuee srg yao T2180 -In thie UMRES Us INSET ¢\10/15,20 at the begining - ie) To insert 90 eas Biep 1: SINAT gtep 2: 1¢ Flest == NUCL then eovtle Undwiffow) ans

You might also like