Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

D a t a Avcture Data hructure i> away of organ

all data items md relatronhip to


intormat ton
Sata > Anything to qive each o+her.
is Calle deta.
Tpes of dato Aructure
&stuentName, AuclentRollno,
There are mainly tuo typu of data
Structure > Repreentaditon of data is Aructure.
Calledructure. Data Aructure|
aph, Arrays, Lis4.
Pvimitue data Non-primitie
Data tructure ShwctUre data rucdure
Data hucture Data + ructure
Ineger lea] Characker Lear Non-i
Data hructure is a way to tore data Ucke] data Shnctn
Ome deata so that i+ Can
ovgam'ze Aays Tres
tacs
be ed &ffitiently beter Woy
LiikLis*
4

L3

3
A-
An Asray Conbe fied os an infinte
Collech'on of homogentoa (Similar +ype)
&lemmg.
Amy are aluays Stored in Conseuhive
Cspecifie) memory Lotatiom.
Array Can be Store multiple valus
wweh Con be referenced by a Sngle nane,
ges of Arayg
SAingle muwuona l mult&Amanuona )
Aroy Arys
Aingle &mawional Array7+ albo
Rnown as
na Dmaunuonal 1b) ATay
Its e y one SubsCnipt to define
+he slemawts of AYrays
Decloratn Decloraton tuJo &imensional Arrun
data-+ype var.name L8xpreAon] Bota-Hyt Vor.mame Iro] [ColomAJ
ex i'nt mum I1o1, ex
in mum L3] L1,
Chor CL51;
Inittal Zation 2-D ATay
Initialiging one-menwional Array
baka.type vav.name Lpreion] / Voluea. =
dado4ype var.name Lrow] [toloma] wlu
int mum Li] {,2,3,,5,4,,8,,1o
i't numLl]= {,2,3, ,5, 6
Char a { *','8',c, b, E}.
[s] Or
multi- bimenunal Arrays multikme t num LaTL] =i,a,3,4,5,2
Ars move
2
hin on Subscript to descrnbe the
Arras &lememds.
Thwo Mmemuonal Avrays I+3 ume tuo
tIL?£
b3
Subscrpt, me SubStip
represRmt rou value nd SeComd nomo3
+O
+o
nu 4
SubSciet to re presen Column Value.
14 maiwy tov motri'x Re presnati
wite a progrum to read& write ome
Stacks (Data hructure)
Ao
Dendnal Aray
+'nclucde <Stdio.h>
tomduredineuhoul Stack a Non- Primtie uinaor doda
include< Conio.h> Structure.
Voi matn C)
Console in put su
ChBCr), 9udo + a n ordered L'st in whith
i n t a Li), i addihon of nw desta item omd oelehbm
ClrsCrC) of already &xisting data item i'3
prink f (Enter the Aray Elemunts"),
End& kmoun
done from Onky me
for (i o; i<=9; it)
0s ToP of stack (Tos)
SCanf (t7d", a-a[i),
POP PUSH
the entere d Amy ' ,
TOS
Print f C"
for (-o; ik9, i++)
Pri (" &\n", a til) Loa oded
ele memt uill be +he
Tha
StaCk
sth), fira tobe Removecd
from the
tack i3 Called
reason
3 Th is the
Loat-in -firai out (LTFo) +ye of Li'Bt.
Oeratims on Stack.
Stock operaHion a Algorithm
There oare two ofera4lom of stack
1PUSH operation>The
proteas of adolu'ng Stack has two Operadr'on,
glement te the top
of stack i PUSH p&Tatiom
a ew
Called PuSH operatiom.
is addung to tack DPop operaton >
&lement
Euery uw
. The procesB of
D PUSH Operadin
top i incrementel by gmg. tlemed
I n Cose the amy foll amd no naw skna Adling a nw
Callee PuSH
of the top of stack i
Can be aled i+> Called Stack fulA or
Stack ouerflow Conda'tibn operation
PuSH operatim Top isireatel
every
2PoP operation >. Th pro Ceq8 of by one.
Beleking an element from the ToP ToP +1
+op of stock i Called PoOP Oprar'ey fu new
I n Coe +he Arrmy i no
After yary fop operatton he adled. +hs Csnd' tion s
elemat i
Stack ip decremenked by ome. Stack ull oy Stack oerflou
Called
If here is no eleme on the
stack and Conation.
he pop is rfomeß han thi's wil}
rult i'to Stack
Underflow Condilion
Algorithm for inrh an
Hem ido2 2PoP Operatim
+h tack (PUSH opradion) The procaAs of deleting an elemunt
from th top of Stack i Called Poe
pUSH (Stack mox S) item) operat'on.
Af+er Every pop Operation the
Step initialze
Sek top -1 Stack TOp detrememted by ome
SHep2 Aepead Steps 3toS Until Top<msije- Top TOP
Step3: Read I+em elememt On the
If thure t's no
pop operat ron
Step4: Set +op >top+1 Stack amd +he
performd thun thu's wil
item i
Steps: Set tack ro] STACk VNDERFLOW
xeaul+ into
Pvink Stock overflow" opeahun
Step 6: Comda+1m.
3 ToP2
3 h poP
20 ToP ToP-
Top-
t Aigorithm for deehing an tem from +he Stocke(Prefix& pokix) SteaCk
Stack Notatn There are +hree
Statk (POP)
Notat'sm
Pop Statk maxSige), Hem) Infix Notatiom whre +he operator is
Repeat Stepp 2 +o4 until Top2o wrHen in- bekuween the opern.
Step +operator
A+B
Set item Stack LToP] A, operome
Step ts
Operator
3Prefi Notation In thi
Step3. Set +op+op- the operomds.
wsiten before
I+em I+ apo knounas polr'sh Nokad(on
Print, No, deluted
is,
Step4 +AB
Undler flows. s
Print toack In tu» operalor
Steps: Postrx Notation
w t e n After
the Opermds.
known as Suffix Notadon
1E i2 also
Ex AB+
Convert the following Infix +o Prefi
Omd pofy fr (A+8)+C/D+£^Fl
Prefiy(+8)»Clb+ eFl
+ABCD +e^FlG
+ALe+
R*C/b+£"F/G (16 podfiy (A+8)* Clb+8^Flq (
RCID+ AEF/
Let EF Ra Let AB+ R
R CID +Rl
R/CD + Ralq
Rx C/D+6FG
Let C D R3
Le+ &F Ra
R+ AalG RX CDt RalG
ARatRG
Let AR Ry R(CD+ Rl
RAa+ Ry LetCD :R3
*R Ra+ Ry
LetRRa=Rs RRa+
As+Ry LetRl=Ry
+Rs Ry
Now &nter he value of Rs, Ru,Rs Ra, R,
+*RR31 RaC
R Rs+R
Let RR Rs
+* +AB/CD/nEF G
R +Ry
Rs Ry t
|DDD DdD|
aweves
veue a Nen-primiive Linear lata
Aructure.
Collection oF slereds
I+ isam hemogento
adced at
in w'ch new elemamk ae
one En Called +he Rear End, amd the
deled from othr
Exisng 8lemet are
end Coalled he front En.
The firt addeel elemank will be +hu tim4
from the queue. that 's the
to be emove
reason ueve i's Called (fI Fo) fiyt-in
f i t ouk type Li34.
In qweue Every insert operation Reor
is inCre mmtecl by o n
R R+
Cwnd esery Releted operatin front
iincremented by on
FalR-1 F: F+
Empty ueue
operadiom on Cueue (23
T o insert an &lemont in a ueue
26R-| F:o Algo GINSERTaUEUE[mil,IT&M
l o20|
Step Initiali3ation
Set front - I
R2F o se Rear= 1
iner 30
1o Ro 3o
Step 2 Repeat Steps 3+oS Until
Rear< moxsize
dlkel &lemad. fia delete lo Step 3 Real item
Step4 f fromt = -| then
20 30
front O
Rear O
delaked SseCond elemend.
R 24 Fz2 eleRear Rear+ |
30
2
Step S Set 8UEUELRear]= item
Step6 PTid, Bueue is oerflow
Deleke an Elemmt from the 9ueue > CIRCULAR UEU
To
is one in whith +he i'nserho
QDeLETE (dueve[moxe, tem) A Cixcula 9ueue
iiTa4
Until front > = 0 of a mew slemut i's done at the vey
Step L Repeat &tep 2to4 LoCation
LoCattom of the qwee if +he laat
Set item : veueLfrond7
Step of qweue is full.
If front == Rear
Stee3 fA
S frot-
SRear =-|
A A Cirtolar queue overtome the problem ot
ront fronk +| unutillged space in Lintar queves implemauel
0 ara ys.
Step4 pint, No deleted is, item CarCular queue has following londt1on
Dfront will aluwa be puihing fivpt
+o he
Steps Priwt"@ueue i EmptybY sleman.
Underflow"
If ront Rear the 9peue will be émpty.
2)
3Eoch hime a n w Blement i3 t'hsertel into
+he queue the Reoar t ntremente by ne
Reor Rear +1
from tha
4Each time a n elembnt i delule
tront is intremantel by
u u e he Value of ono.
front front+}
Insertan &leman in Chrculor 9uewe 6 6eue (Dota &taucture)
aTNSERT (CRUEUE LMAxSI ZE], Iten 0peratton n 6ueue
Algo
Step iF (frod= =(Rear+). masie) 19, 30, 39,4o
wyite queue is overflow Exit, ) front marSe-3
Pear- eme eye
ysee
ele toake the Velue
a 3tos Stap Repeat
if Cfront -) Amase-
Aront O -I <3-1
Rear O
-1<ge
&lae
ReoY=Rear+)/, maxSiz) 3Read item
Reod lo
ASsgn Valae ueL Rea] Value. f:-
en&F
S+epa vit
9 C o item
Se
R At DELETE an &lemant in CirCular 9eue
R Itl 2
set 9,R]30 Algo QDELETE(Guee [mosu] 1+em)
RearMaxja-|
O <3-1
O rue
10 20 30 D f (front -1)
Wrte Oueue Underflou Cne Evi
Rea 20 Rearmarje-1
F f:z -| item ueue frond7
a<3-
O- faL4e f (front = Reov)
R Rt 9 eue s overflew Set front -
A 0t1 Set Reav - I
Elae front ((front+), mavse)
endi S4ademe
tem teel
2. evit
Rear mauje -|
+ue
Read 30
O 1 falag
Elae
UEUE (Dota Structure) (
Selete oeratron ueue
l o Ro30 ma se 3
R2
F-0
Set tam ,Lo]
tem I0
O=2folae
elae
f Otl
tam Ite
203o
fl Rz2
| 20 30 4) tem Reletel Linke 1Li3t8
f 1 R:3 ructure, in
A Li'wked Lipt isa Lintor duta
not Mored at
Coe 2. f>:0 f- Wh'ch the Elemewka
are
e
> 0trse A- Lo Catlom.
Contigusu mamory
Hem 9 7 F> O Structure
dymane clota
tem 2
-|>20 ¢alae A Linkel Lis+
1s a
Li> t 3
mot fixed
Th No. of
noes i'n a
f f= =A tap 5: 90e0e iB Eme one h r i k
on demmd
Cmd Can grow
falae ueue , Called a n0ke, Whch
elae Underflow Each 8lemavd i
f Ft
f 141:2 hou two part8. intormation
tore3 the
item ' eleked info part
which
mex4
20 dulekel whuch porntto the
Poi'nter
Omd
3 03 0 &leman
F: R2
1o
info Poie info pider
Noo-e
a tem 4 1
tem 3o Sforc? Ento Enfo -no
3 f f: : A
s f-
Alvamtags of Linked Li'ats Operaton ON Linked Li34: (34)
The Bauc operatim performal to be om
Linke u3p are dynamc data stweiure:
Thad
think
+he inkel Ligt are
,they Can qrow onc
+he exetut1on of program. D Coeati'm Th'» operatiom are ud
dun'ng a
Efficiert memeory U4ilzation: Here, memor
+o Cre ate a Linke Lii. Zn thijs
mode 3 Created Om Liwked to +he
not pre alleCated. memoy b allbatel
-
Anoher mole.
whenever i+ reuired. And i+s dealloCute
2 InSert1on th3 operat1on 1 usec
Remoued) when its netomger neecde
+oiney+ a nw nocle i'n +he Linked
3Inserton Cmd delettens are Eaier
Om ef Frcient I+ PToule LiB+. Aew nee may be tnserteck
i'n
flexibiliy A +he begimung of a lindeed Li'%
inerting a data item at a Specifred
end of Liwked Li3.
potion ownd delekton of a duta
1tem
A+ he a
Hinked LiM
A the Specifie posion
from the in a
given posilion.
mowmy Complex APpCattons Can be Deletion+ Thp operoattan sed +o
rom
item (a node)
eoly Comied ouk with liked ipts. dete an
h
+h iked Lia. A noe may be delded fon
lieed Li4
Beginmuig of o
Linke8 Li4
end of a
poaion in +he li4,
Specfied
TrouerbingI+s
a proca of going pes oF Linke Li'a4 (36
the nodes of a Linke
thragh all
End +o +he
othr rd. mre are
tour p s of
Lip+ 4rom m e aCally.
the procesk of
Liwked Li'B+.
ConCatenaton I+ ih Whth
1Singly-Linkecl Lipt >T+s
+o 4he Er me
+h Selomd
Li3t
joining all nodes are hwa
of 4he 4Y i3
seX
togetherin Some sequemidl manner.
'
Tu'> operaln I t albo Callec Lihear ike hit.
splay moodes
to prr't
Each CAme Every Stor
nformoadim.
ts in whch al)
22dovbly -Linked List
one
nodes are liwked
tozether by
in ACCemin both
mulhple L'nks which hulp
the Succeor
nocle CNext node) and predecoMor
nodse) within the Ligt.
node (Arewoos
the lu34 in the orvard
Thus helps to thrauerae
backaard dection.
direchon omd Lo4
SHo Prev tada
3
Grtular Linked Lipt >T+ Sne which hag
33
no bginy Omd no End. A s ly (39
Linked Lipa Can be made a Gitulay lihked List
by Simely Sertig+he addrea of the ery
frp+ noe in he Lik fiell of the Losnooe
30
4 Cirtular doubly iwkeel List It's one whth
ha beth the Succeaor
poinder omd predeCeakor poiter in o
Cirtular monmer.
Asdr
T30
nke .
nserting Nocus in iked
(38) o a79/30
Inserttng at he beginnung
the Lip+
of
+he Encd of +he Lig4
Inserting at
poution
Speci free
3 Inserthing a+ the
wthin h Lig4
Sharre
3
307Yal
LENRE LEST i'n uked
LINKED LIST
Ingering A Node AT the egi'nnung Linked
end in Sinaly
Lipt Insert A Node AT The
L+
Algo hm
INsE ATFIRST(START, TTEm) Algosithmn
Lnsert. o t (STARTr, I TEM)
for ouerflow
Stept Lcheck
StepL Check for overflow
NULL then NULL then
I f P+Y -
TF PT
PTint ouer flou) Print ouerflew
Exi+ Ex i4
&lae of (Node) ele
PTR (Node t) mallec(u PTR (Nde ) malloc (sizeofe )
Create n e w node
from mmory cmd
acdeisres t o PTA 7+em
a s g n i+s
Stepa Set PTR> Info
NULL
Stepa S PTA INFo = Item set PTA>ext
Step3
NULL e l #hm
Neyt= STAAT IF start :
SteP3
Step3 SPTR Step4
Set START: PtT;
Se STAAT PTR
Step Loc= S t u r t
StepS: Set
until loc->NetM
Repeat Step 7
nade 2 made Step6
ra nedhe
Step Set Loc Loc Mex+
After i r tin
Stepg: Set Loc Neyt Y
L2N kED LTST
LoC
Sto Fosihion in
a Noole at the Specified
Inerhng
- Singly Linked List.
o new node
PAY Algorithm
Inser+Locaton (START, Item, Loc)
After Inser+ion Check fer overflow
Stepl
IF pr== NoLL +
Se PTin oerflow
Nodemallec (sie ofWo)
Phr
ek P r I N f o : iten
Step2
+hen
Step3 If Star =NuLL
Set Stot ptr
NULL
Set Phr Next
Counter I m Porinkers
Step4: nitaliye the
Set I-o
Set temp Stevt
Steps: Repeat Steps 6 Cmd until < Loc Deleting Nede in Liwked ip4
Step6 Se temp - temp> Next
set IT4 Deletiinmg a nooe rom the Linked
Steet
Step8 Sek ptr Next temp->Ngt L'pt has three 'nakomce3.
Sek teme > Next+ : Ptr
Step 9 L Deleting the tir+ node ot
of
SHar em
+he Like Li'Bt
o
Dele4ing +he Lou noe of
2
rF
he Linked LB
After Inserhom
Specifies
Dele4ing he madle trom
SHor 3
POBition of the Livkel Li's

You might also like