Data Structures Part 2
Data Structures Part 2
Nae in ngly Linked Lip+ beletng the Lat node 'n ingy Linked& Li's+
Deletinghe fivat
Algorthm
Algorithms
deleted is+ (START) Deleng (STAAT
Under
flow
StepL: Check fer underflew
Check for
StepL I f t r NuLL han
=
NULL, thun
Stat
If Prink Lik Li's is empky
Pi'w
uinkel Lst Empty Exit
I emed poinkers
Tni'tialze the Counher
Step 2
Se+ T : O ;
Se p r Star
set PTR
= PTR Nex+
Steps
T+1
Sek I :
Step
Step7 Pri blemunt deldel is=PtY>ifo Tree Bada stuciure
So
P*r>Nox+0 T s e e . A Tree a non -liinear lata
set Temp- Neyt
=
Step 8
Structure in whu'ch items are
Step9:ree (P+r) aTomged in a Sorted sequemce.
Acnta items.
Root Levdl o
Afte e e t i o n
A
Levt
SHo Leuel 2
Levd 3
Tree TesminologyTree hos A e t
texminology Such as+
LeftSuetree ( ) roo
Toot
k Ri'yhk Sub+ree
ypes of Binary
+sees>
TroueTsal of a &inary ee
ary 'n which each node
D full nary +reeA
ful
Euery I+ o way
's is ViBited Exactl nC(e
Tsee
T ree i'n +he +ree
a Chl manner.
node haus o or
n a Syptematic
We uge
There are three way8 whuth
tree Noe lestRigat
-
+o +rauerse a
L- Pre ovler
troueTBal NLR
tronserBal (LNR)
nary treeis 2 - I n oreler
tree A +xaversal CLAN)
Complete
hary
Tree 'f
all Levels
are
3 PoB+order
2 inary the L o
1Preorder Trauersal In ths
Complete
fille& Ex
Cept Possibly Lef+
Compl e te ly keys as
TaaeTsal method, he vootoke is
all
+he
L0t Leuel hag
Lesel omd Leuo
0 p o b l e .
e d t a: 2 vibited tirpt, +hen +h Le subtvee
Lesl a 24 Ownd finally thi riA Sobtree.
Leds a Algothm
TreeA Tre
i'ntukthal) Until a| nodes
ase trauerBed
-
3) Perfect nary
rodes heus tuwo
CAildren Cmcd
all iwhermal
a t +he Same Leusl Stept Visit xoot node.
Leaues are
chi'd +raverae Left Subtree.
in wch all Le wl heus
Stepa ReCurgiuely
Leo Le +rauerAR Right Sobhre
Step3: Aetursively
Led
Odo6ooady
8 Sinary Seorch tree (8ST)
inery SeoTCh tree anode- buyeA birary
( +ree dota Struchure whch hag 4he folloiing Rules
L The value of +he key in the lLeft chuld or
leftSubtree les8 than the valueof roo
Pre-order +saueTaal 8
The value of +he key ih +he iht Child or
A,B,D,E, C, F, iot Subtree i more than or Eaual to he roo
D, B, ¬, A, F,C, mathed
Trasersal In th'
3 9 Pobt-order the rame
Vigited Lak, hente
+he root node iz
fir3+ uwe tvoerse Left Subthree, then the
h e ToO4noe.
riSubtree omd finally
Algomthm
are
traserSLd -
S+aCkK ueue2
Collecthien of
1 I+ represe nbs the Collecion of
1T+representsthe
Lat i'n fi»t Ouk (LIFO)owkelemunds i'n Fipt Zn Fip4 ou4 (FIFo) oxder
elememts i'n
are i'nserted oamc
2Objectp are inserted amd
2 0bects
removeed from dfferent Encs
semoved at the Same
end Called
Called front omd r e a r Ends.
Top of Stack (ToS). Called
operation
I n r t operation is Called 3Iner
3 Enqweue Operation.
push OAeratn.
3 74 is Easy +o 3 I+ is Afficu4 +o
mplemand.
implemam
4 Data &lemans Can Dota tlemunta Com'
be hsauerael in a be trouerAed in a
Sngle Aun only. ungle Aun omly.
SMemery 1 no+ Smemory uhil'zaon
4iled in a &fficrert 'n an £ firent woy.
ATsay Linked-upt
Aray i tixed LSize of a Lit 's not fixed
1 Sze of an
Collecdion o
Collection of
a Liwked-Li's+ is a
Aray a
2 Homogenesus (Similardala type node Cdata 2 addres)
allocoated froom
alloCate trom 3Memory
3Memory
Stack.
heoP
i+h S4atic 4Liwked-Lit work wi'th
4Aray work
bymamie data Strueture.
data Structure .
a r e Stored i'n
Elemanks
5 SElements Can be Stored
Comtigusus memory Locohioms.
Cwy where 'n the memory
6ATa Elemanbs are i'ndepen- 6Li'nked Lis+ Elements are
dem to Each other. de pend +o &cch other.
Assay 4ake more +me, bLinked-Li3+ ake Less 4ime.
(TneTt1nL belethbn) &
( Inser+ion beletin)
Difference between Tree omd Groph 6
Txee Gasaph
1+Tree is a Collectiom 1 raph isa Collection
of nocus omd édge.
of verties/nodes amd
& T: inode, Edaes 3 CVv,ej
There i's a Unuaue 2There is no unique
node Called oot intree node.