Witte a Program +0 1299 Y write one Stacks Date Structure)
Dimention al Array. io
Include € rain" in e [e Stack Is ar Alon - Primitive Unear dara
include < tonio.n >, aa Structure:
Cirs (70), Jaren) |° Tt ts an Ordered list tn Which addition of
Vois main ( ) new data item and deletfon ef already existing
{ nta iol, i; dara item is dont From only one End
Qrs(rc); Known qs Top of stack (Tos )
Print E ("Enter thx Array elements”) ; Pop <— Push
for Uz0;, 1<=9; , itt)
ES
>
Print E (“the entered Array 167);
for (i=0; 16-93 ++)
Tos
Sean€ (" 13 anio a
Conse (Pin aa)
e The last added element 10) be the first +0
be Removed From the <tatk-
Tris 1S the reason crack Is Called
Last-ln-pirst- out (LIFO) type oF st
Oferarfons on Stark Stack Operation £ Algorithm
There are two operation of «raw Stack has two Operation.
1): Push operation.
1).[Push operation :] + Tu process OF adding 2). PoP Operarton.
q new element to the top of sta fs called
1).|PusH Oferarion Tu process of adding q
ery New element is adding fo statk top | new element of the top of statK js called
remented by one |_PusH Operation —
+ In case thy arroy ts Fall and no new element |. Every Pusy operation Top is Incremented
can be added it's called Stack full or by one
Stack OverFioW condition.
Toe = TOP +1
2)-|PoP Operation 1) + Tre process of dusting an
element From th top of Stack fabled ° In caso te Avroy ts Lun no neto element
Por operation, 5 ts added - this condition js called
+ After every PoP operation tr stack (Tor) is. | Stack fuit 01 Stack Overfion Lonai#on.
detrimanre d by One.
+ IF there is no element on pu stauc and thy [AF Algorithm for Yncerting an item Into
PoP ts performed tron Hs Win result Into pre Staus (Pus Operation).
Stack underFio® Condition. Rs i)
UC Keun Ae
Posy ( Stack Umax size], item) # Algorithm for deletIng on Mem from tne
Step i: inidatize
Stack ( por)
su tops - POP ( stack [max Size], item)
Step 22 Repeat Steps St S uni Top<moxsize-1[Step1: Repeat steps 2404 until Top 20.
Steps: Read Item
Srepu: Set sop = toe t
Step St Ser stausltop] =item
Step 6: Print " Sta overflow”
2. [Por Operan]
* The process of deleting an element From
th top of stack is called PoP Operation.
+ Afrer every POF Operation + Srauc To
is decremented by one
ToP = Top -1
+ If there Is no element on Eu Stark and thy Tr is also Known qe Polish nlotatton.
PoP operation is performed pun pds vol result] ex: +AB
inro STACK UNDERFLOW. Condition.
3)1 PostAlx alotatt on : y y 7
2] “por operen A POP In anis operator 1e written
Bodelered [20] Tor=2 |_| after the operands.
108 It fs also Known as Lurflx notation,
Ex AGB+
Step2: Set ttem = stack CTP)
Steps: Ser top = top-!
Srepu: Print No. deleted is, Item
Steps: Print stack under Flows.
1). [IMF Notarfon ] Winere tne operaror is
written In between the Operands.
Ex: A+B + Operaloy A,B Operands
2) [Prefix notarlon :| In mis operator Is writren
before prt Operands .
20] TOP >Top-1
16 221
PostPtx > (A+B) x Yo + E’F/a
(AB) & clo + E*F/q
@> Convert the Followina Infly to Pree lx and
postFix Por (A+B) * C/D +E F/G
Prefix > (A+8) x cp + EN Fla
+ AB K C)o + EN F/G
Let + AB =R,
Ri& CJD + E"F/G
R * c[p+ REF] q
tu > NEFSR2
R,k YD+ RIG
R X /D+R/G
CENAS
Rx Rz+£/0
Rik R+/RQ
RQ =Ru
RX Re + Ru
HK RıRz + Ru
er HR, Ra = Rs
Rs + Ru
+ Rs Ru
rine Value of Rs Lu bs, Ra, Ry
HER EE malas ee
+ € +AB/cD/neFQ
POPE
Let AB+=R
RIKC/D + EF/g
Rx cin FEED!
Let EEN = Ra
Rik C/D + R/Q
RK ON + JG
ter coy = Rs
RK Rot Rala
Rı ® Ra +(R2Q)
Cer RG =Ry
Qi X Re + hu
+8y
Let Risk =Rs
Rs +Ry
Rs Rut
Now enter tre value of Rs
Re Rut
O Rx Lu +
AB+COP« Roe
AR + CD/ x ErNal+
Ra Rs, Ra, R,
Postfix expression %
Ext convert (A+B XC) Into prefix and postrix symbol Seanned a [ex Presston |
<
using robwar form € €
# +0 Convert In Prefix PonowIng operation x cB
Proaram Cr CBx
c+ CBA
ys Reverse the Input string > a, Le
2). Perform tabulay matnod and Find postfix >
Expression « So tne postfix Expression CBXAT- Now
3). Reverse tnls postfix Expression sting to lors ante Expression te ger the prefix
find the Prefix. heen
so prefix is +A BC »
Exi- A+BXC (estas N freele,
First te add branches + Convert postelx > Diver perform rabular
A form (A+B *C)
RAA BE [Symbol Stanned] Strack
(cxß+a)
[Prefix and fostfix using tabular form] [rabusar im | [Stk] [Postfix
Priority
N.> Highest
k,1= 2 highest
+= 7 opera,
Poste Expression = ABC ¥ +
Insert 10 peo #F-0
* Queue is a Non- Almitive Unar data structure.
+ Tr Is an homogeneous contaron of elements
In whith neu elements are added at one End] insert 20
Caied thy Rear End, and the existing
element are dered from Other End Called
Pu Front End
+» The First added element vill be Du First 40
be remove from thi queue. thor Ts the Insert 30
yeason queue Ys calles (FIFO) First- In —
First our type itt.
+ In queue every Insert operation fear Ys
Intrementtd by One. Auen element. First deere 10
L=Q+1 R=2 £ F=l
and every deleted operation front 34 Br En! sel
incremented by one rar
F=F+)
Le! delere Second element
Operation on Queue
»[7 deere an element from the Queve]
3) [To tnserr an Element In a Queue a1
Algo: Qinseer [Qvev_ [moxsize), Trem
IntHatizatlon
<et Front =
sur Rear =
Repeot Steps Zt 5 um)
_Roar < Maxsize =) _
Read item
Stept:
Step 2:
Step 3:
Srep us
Rear = Rear t|
Ser Queve LRegr] = Prem
Fant , Queue js OverfloW
Step 6 :
step 6 :
Gbeuere (Queuelmaxsize], item)
Step 1:
Step 2°
Shp3:
Stepu:
Steps:
Repear step 240 u unt)
front >=0
Su trem = Queue [Front]
If front = = Rear
set Front =-)
Sur Rear =-)
else
front = Front +)
Fant, alo. Deered Ye, rem
Print "Queue js Empry or
Undeyflow
RCULAR QUEVE 3)- Each Hme a new element Is Inserted Into
the queue the Rear Is Incremented by one
#- A Circtuay queue is one In which the Rear = Rear +]_
InserHon OF q new element ts dont at tha very u): Each time an element Jared From the
Arst location of the queue fF the lack location queue tra value of front Is Incvemented by ont
of queue is full. old ec Front = Front +1
F=RS-1
insert an element In Clyuulay Queue
% Aigo > Ginsear (QUEUE Lmaxsize]
a La] Step 1 2 1F( Front =
Orlte queue ds over Flow X Exit.
# À Grewar queue overcome Hu Problem of Else: pare the value
Unuttized space In Linar queues Impiemenred te ( Front 1)
ag arrays Ser front =0
Rear =0
Cirevlar queue has following Cond{Ho Else
=(Rear+i) 7 maxstze )
Rear = (Crear +1)7- maxsize)
1)- Front wil always be pointing to pu First [Assign vaiuel Queue CReav] = value
element: Lena te].
2): IF Front = Rear ti queue wh) be empry
ueue (Paka Structure)
OPeratton on Queue
isa
Maxsize = 3
+ Front = 42 Empty queue
Rear = -1
3 FOS step Repeat
R < maxsize -1
PGE
ió JU
y
sus
Read them
Read 10
10, 20,30, Yo
ser q [o] =
Y [o] =10
quese [el T7]
va Ud 40]
F=0, e-0
Rear< maxsize -|
0<3-)
0 < 2 true
Read 20
fe +t
o 1 false
Else
R=R+H
R=04)
(RES,
+ JD = 20
151201 ]
Ya 46) 912]
Feo, R=)
Sub Rear = -1 Else
Ciset Front = (Cerone +1) 1: maxsize) e=FH
Lena 1€ srarement ] C= Ort =
— ¡fem deleted:
u). trem is queres
2): ER,
tO is darered
Queve ( Derg strutrure )
[Lo [30]
Daere oPerarion On Gueue.
maxstze =3 Yo) Ji] 90)
Ext 10 [20 [zo
91) 909 962)
Feo R=2
prc Homar CLINKEDIN),
1==2 False
else
F=6+i
Fe =
Srem is dered
20 is daered-
lazo
Fe2 R=2
Case
D: F>=0
Do vrue
2) trem = Y (2)
Them = 30
gr ie p=
2 true
eS
4} diem Is dutred
]
Casey).
F>=0
-1>=0 False
Ships: Queue Is empry
fs Undev Flow
+ A Mnkid List }s a linear dara styucure,
In OH que elements Qre nor stored at
Contiguous memory Location
° A Nnlad Kst 15 a dynamic dora structure .
Thu no. of nodes In a Mist $s not fixed
and tan grow and shrink on demand
e Each Element fs called q node Nth has
TWO parts.
Ingo part wnith stores pre \nformarton
and Polat WNth point fo pu next element.
[faro pointer | ex: [iofizsu
Node ito VPetarr
EX (staan
CE fmrofpoint, INGO [Porra INFO)
Ext- [start
—e O EX]
AdvarBges of Unked Usts
1)-|Linked List are Iynamlt data structure :
Thar fs, they tan groW and shrink during
Pu exeution of à Program.
2)-[EFFfctent_ memory utfifzation:
Here, memory ds not Pre- allocared. memory
TS atlocared Whenauer Ps required. Ana It's
deatiocared (Removed) puren Ye no longer
needed.
3) [Insertion ana acietions are easter Zt/fiden
Tt provide Plextbility fn Inserting a Jara
item ar q spedeled Position ‘and dueulon of
a data trem from pu given position.
y) Many tompitx Apputations can be easily
Carried Ouf Wwirh Iinad lists»
ATULKOMAR CHAKEDIN) .
[Operadon On Naked Ust?
Tu Basic operation ro be performed on re
Linked Wists are t-
D: Tris operation are used te
Creare a Linked Aist In this node Ys
creored and Untied fo ft another node -
2). [Imserton] TAs operation Ys used to Insert
a new node Tn the United Note A new node
may be Inserted.
> At the beginning of a Marked Ust-
> At pu End of a Uniked List.
> At pre cpeufied posiHon In a Mnied Net.
3) TNs Operarion js used joa Uere
an rm [a node) From pu Ainiced Mist. A node
moy be daered from
- Beginning of q Unied alst.
nm End of a Kinked Aah.
> Spedfied position tn phe List.
4) Tr Is a Process of going
through all the nodes OF a linicd ur from
One end fo ru Omer end.
5)-[Concatenarton 1] It's pu process of que
jelnino pu sitond ist 10 mu end Of pu
First liste
6). [Display : [TRS operaron ds used to print
each and euzry nodes Information :
Tyres oF Malad Ast.
+ Basicatty , there are four tyge of Inked st.
» TUS one to o
ajinodes are linktd pgumer In some
seqguental manner. fs also tale dAlnenr
Jintao Uit.
[sroer_]
2).[Doubly - Linked List t] Tt's one fn
neh ail nodes are linked together by
muitipie links WHA nalp In accessing borh
pu successor node (Next node) and
predecessor node (Previous node) wsikhin rhe
Mist. Dis nap do traverse the list In pre
fortoard alvettion and bauwward direulon-
START i eer Last
— ev Dai Suce face
LÉ u
Prev Daba Succ
3)-[Cirewar Untied Kst} Tes one wich nas
no beginning and no end- A <Ing1 linked
AIS Can be made a Creular Iinted Iict by
Simply sorting the address OF tre very Alsst
node In Pre tink Fleid OF tha Last node-
Es
Ha
LinKEDIN),
4) [etrewar doubly Uniad List 2 | TS one
Wich both. re Successor pelntey and Predecessor 2).
pointer in a drewan manner.
[starr] „Age oF 10 7
SAA]
Info address
| < 7 | Herten
£ [el EE el ET = = = 7
£ = 10
Aas! oF
Inserting of Nodes In Unked List
1). TnserHng ar fu beginning of the List.
2). Inserting ar the End of te Not.
3). Inserting ar pu cpedfied Position wide
bu Mist
START
Ha
Aryı komnr CLIMISEDI),
[Loken ua]
Lnsarting Q_node at tre Beginning In Hnjud In nad
Ust Insert a node or thi end In singiy Ward,
Algorithm >
INSERT_ FIRST (START, tem) Algorithm >
Step1: [ Cheuk For overfiow] INSERT_ LAST ( START, ITEM)
If Oty = NULL then Sa
Print overFiew Step 1: Chex for overflow
Else ei IF Pty = NULL then
PTR = (Node x)manoc (size of (node?) Print overflow
4 Create new node From memory and die
assion ts address
on à Tess 40 PTR Pre = (Node *) maroc ( size of
Set PTR > INFO = Item (nosed) 5
SU PTR => NAxt = START
Set START = PTR Srepa: Ser PTR > Info = Irem 5
Steps: Sur PTR > Next = Null,
Srepu: TF <tart = NULL and pun
SU STAR (ty.
elses
elo node. Steps! Su Loc = srart
After InserHon
fr ED F0 EX]
ATULKOMAR CLIAIKeDint).
‘START
LINKED LIST
Srep6: Repeat step 7 Until Loc 4 Next! aioe}
Step?! Str loc = loco Next 5 Inserting_ à node at pu spedfic Positton In
Steps: Su loc — Net = Pres Singty, inked Ist
Algorithm >
Insext_ Location (start, Item, Loc)
Step1: Che for dverflow
Bel If Ptr= = null thin
Print overfiow
Exit
After Inserton. else
Prr= (nose) maroc (size of (nose))
Sttp2: Ser Pty > Info = Trem
ShpZ: JE start = NULL fren
Set Start = Per
Str Pry ont = null
Step ut Initigtize +hi Counrer T and pointers
Ser 1 =0
Su temp = start
Steps + Repeat steps 6 and 3 unr Le Loc
Step 6! Ser temp = hemp > nut
Step?“ Set P= [th
Steps! Let Piro N&t= temp 7 next
Sepa: Set temp — Next = Pty
Dereting the First nlode in SinGiy Unwed List
ee ee ee
Deleting tne rast node In singly linked List
Algorithm > >
Algo dtnms > Deseting ( START)
Daured First ( start) Step 1: Cheu< For Underfiow
Stepi: Chew for under Fiouo If start = NULL pun
Tf start = NULL pun Print Liniad Hst Is Empry
Print Unwed Ist Empty exit
exit Stepat Tf <rart Net = NULL pun
Srepa: Sat PTR = START Su Pry = Start
Step 3: Sek START = START = Next Seu Start = NULL
Step 42 Print Element dared is Pty > info Print element detered ls = PIR > Info
Steps: fr Corr) Free (PTR)
Eng le
Step3: Set PTR = START
I Br EE SHEP UL Repeat step S and 6 until
PTR > Nort) = NULL
Steps: Ser loc = PTR
After delerion
[staat
SAA
PUC uma (LINKEDIN).
Step 6% Sek PTR = PTR > next
Step +: Set Loc à Next = AU
Step Bs Free CPTR).
ATULICOMAR CLINKEDIN) à
[Erico usr DELETING MODES
Derertng tne modes From SpeuFled
Position in Singty Uniced list
Algorithm >
Deere - Locatfon ( START, Loc)
Step1: Cheu< Por Under Flow
IF PAR = NULL prin
Print underflow
exit
: Intriattze pu Counter 1 and polarers
Su f=0;
Se Pry = start,
Repeat Step u to 6 unri]
I < wc
Ser temp = PTR
Sheps: Ser PTR = PTR > Next
Srepes Se I=1+1
Step: Print Clement querea Is Teees In Data steuerure |
= Pry = Info on-Iinear dara struuure
Stews: Set Temp > Net =r > waxt Wnrith Trams are arranged In a sorted sequence
Srpat Free (ptr) + Tt ts used to vepresent Wiayarenlcal
yalatton ship existing Qmongst several gota
items: gr Ar Level O
Lever 1
Led He] } ol Level 2
Pty [m] Lever 3
vee Terminology :] Tire has aieferenr
After deletion.
START
& terminoiogy such as :-
La 1) [ROOF] It 15 speviany designed dara trem
19 Yn a tree. It iS Ane First In the hitvarovcal
of nodes In a given tree. In the given tree
tne nlode A and nedeT has maximum slog reels)
So the degree ef tree is 3.
s)-[TEymTaal none à] A node wlth degree zen
Ys called terminal node. In given tree —
E,3,G,n,K,Land ™ are terminal node.
[Ron Terminer Mode] Any node iahoce
degree 15 not zero Ys called non- terminal node,
In oluen tree- A,B,C, D, FT are
non- reyminad ajode.
a) [Sibitags +] me child nodes of à given parent
node are Called Siblings. Thay are also
called brothers.
In the given table.
- B,C,D are Siblings ef Parent node A
8)-[Leuel ] The entire tree structure ts Leveled
In such a Way that ti yoot node 15 always
at level O.
9.[Eage:]ır is q connecting line oftWo nodes.
snot is, qu ino drawn from One node to
another node fs Called an Edge.
It 15 a Sequence of tonsecuiive edges
From PAL souru node to FAL destination node.
In re given tree the pam HW À and J isas.
(a, 8) (6,F) ana CF, 3)
ASE
u) [Dep] se 1s pu maximum tevel of any
node {na oven tree. In the alven tree, ma
yeot node A has the Maximum Level
12) [Forest tt is a set of disjoint trees. In a
aluen tree fF you remove Its yoot nose ren It
becomes a forest. In pu otuen tree, there 15
forest With three tree. <uth Qs.
After yemoving root A. Forest Is