0% found this document useful (0 votes)
177 views

Data Structure Notes Part2 Csegyan

The document provides an overview of algorithms and data structures for linked lists and trees. It discusses steps for deleting nodes from a linked list and the node from a specified position. It also defines common tree terminology such as root, node, leaf, edge, path, depth, and binary trees.

Uploaded by

Devesh Saxena
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
177 views

Data Structure Notes Part2 Csegyan

The document provides an overview of algorithms and data structures for linked lists and trees. It discusses steps for deleting nodes from a linked list and the node from a specified position. It also defines common tree terminology such as root, node, leaf, edge, path, depth, and binary trees.

Uploaded by

Devesh Saxena
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

LENKED LIST DELETEAG NODES ( LINKED LIST DELETING NobéS h3

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
Stepa fStart Next NULL hem
START Set Phr : Start
set PTRz
Stee 2 STAATNax
Se start= NULL
STAAT =
set
Step 8lement
delcted is phr>ifa Pit elemamt deluked is PTR >Info
Print
S+ep
StePS free CP). free (PTR
endf
Stoe PTA START
Step3 set
S+ep4 Repeat S+ep Somd 6 Until
A f t e r &eielion PTANext =NULL
PTR
20 Step s: s t LOC
Set PTR= PTR Next
S4ep6
Sek Loc Next NULL
48 LINKED LIST DELETENG NODES 49
Stee Specrfiecl Position
belehng the Nede from
Step free (eTA)
In &gly Liwkad ui
Star LoC
Algorithm
Delete LoCation (STAAT, LOC
After dehion Check fov Under flow
Step L
Sstarcd f PTA: NULL them
priwt Underflow
I emed poinkers
Tni'tialze the Counher
Step 2
Se+ T : O ;
Se p r Star
Repeat Step 4 to 6 untl I< LO
Step3:
Step4 Set+emp PTR
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.
hierorchial
T+ URed +o xepresent
Sto TemP xelatonmp Exigst1'ng camongst
Seeral
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+
1 Root >I+ i» Special Begnal elata
the firs+ i'n the
tem ina tree. I+ 1s
dlata item.
hierarchutal Aromgemak of
+em.
In the above +xee, Ai oot
data item in a +ree
2 Node Each
sCalled a nocle. In the qiuen
Txee+here are 3 NoRle Such as 7 Siblinga The Child nodes of a gien
A, 6,C, D, E, F, 7, H, T, J, K, L,M Porennode are Called S.bling. Thy
are alho Called brothers.
no. ofF
SDearee of a node T+ 8 the In the en +able .
Subtree3 of a nodde in a uen tree B, C,D are SiblingH of porent nod A.
The deqree of A = 3
H&T are Siblings of parent noole D
The degvee of C =1 enkive +ree shruxture i
of L = O 8Level>The hat +he
The legee Leve lled in Such a uoy
maxinmum clgree a level Q.
Degree of o ree7 the xoot node is aluways
of nases in a gisen +ree. In the given Connecing Line ofP
9Elge> It i
a
+Tee the Nocle A mel node T heas moximum drawn
+hat s, +he Line
+uwo nodes,
degree (3) so tht egree of tree ts 3 noe is
from node +o another
ome
S Terminal node A nooke with degree Calle& an &dge.
3ero 3 Calle erminal node. In a Seqmte of
loPath I H
ise +ree - E, J, C7, H, K,L Omd m are +he Source
Conselute edq, trom
+erminal nede deutinadiom node. Tn
ode +o +he
6 Nona-termina Node Any Noe who tree +he path
btween
Called non-termuinal the giuem
ecree ip i
not r o
A omd s.
node. 1n g n tree - A,B,C, D, EI are
, F) Cmd (E, T)
Non-+exmunal Node . A, B)
A 8 F>J
1Depth It is the maximum level o
noce in a Puen +see. In
4he 8TNARY TREES
Ony
noke A hauy the finite set of
e n +ree, +he Yoot Sinary tree is oa
maximum leuel. item which s Either mpty
data
se of Bjoint item Called
12 forest I t ias hg le
a
of Coista of a
+xees. In a qian +ree tf yoy
t u o disjoink brnary
TOOt d
yoot node +hen it belomes Subtree md
Te move +
there is
tree Called + h Left
the gion +ree,
o toreg. In oigh swbtree
+ree, Such cy.
foxes+ with ree
voot A. forest ib. mede Can hae
After remonng
I n Binary +ree, Euery
are
Children which
moy 'mum of 2
Left Child
od Arght Chd
Known us
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 +reeAf u l 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
hary
tree A
Levels are
PoB+order +xaversal CLAN)
Complete all 3
2 Tree 'f
inary the L o
1Preorder Trauersal In ths
Complete
Ex Cept Possibly
fille& Lef+
Compl e te ly hag all keys
as
+he
L0t Leuel
Leuo
TaaeTsal method, he vootoke is
Lesel omd
0 p o b l e .
e d t a: 2 vibited tirpt, +hen +h Le subtvee
Lesl a 24 Ownd riA Sobtree.
finally thi
Leds a Algothm
TreeA Tre i'ntukth ase trauerBed
-
3) Perfect nary Cmcd al) Until a| nodes
CAildren
rodes heus tuwo xoot node.
all iwhermal Visit
Leaues are
Same Leusl
a t +he
chi'd
Stept +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
2 Inoder TgauevBal In thi's
(L 3The Tiaht Omd Left Subtree eoch
is
raueral mthol, +he Left Subtree mupt also be a binary Search tree (8s)
frat, them +heobt omd loter
Vipited
+ ri ubtree.
Algothm
ae trauersed-
Untill all nokes
toverse Lef+ Subhree
Stepl: ReCuTBively
Vi3i+ Too+ noe.
Step2
Step3: Retwrsively +roserR
Riht
Subtree.
(aToo+
Inorder Taserzoal -
.
D, B, ¬, A, F,C, a,
Trasersal In th' mathed
3 9 Pobt-order
hente the rame
+he root node iz Vigited Lak,
Subthree, then the
fir3+ uwe tvoerse Left
riSubtree omd finally h e ToO4noe.
Algomthm
are
traserSLd -
Untl Al nodug Let subtree.
Step ReCuraively traerae
Subtree.
+rauerae right
Step2: Retursiuely
Step3:Visi+ xoot node.
roo
ex
Popt ovler TroseBal 1
A
O,E,8,P G, C,
Differente be+ ween Stack Cmc
S+aCkK ueue2
1T+representsthe
Collecthien of 1 I+ represenbs the Collecion of
i'n Fipt Zn Fip4 ou4 (FIFo) oxder
elememts i'n Lat i'n fi»t Ouk (LIFO)owkelemunds
oamc
are inserted amd 2 0bects are i'nserted
2Objectp removeed from dfferent Encs
semoved at the Same end Called Ends.
Called front omd
rear
Top of Stack (ToS). Called
operation
I n r t operation is Called 3Iner
3 Enqweue Operation.
push OAeratn.
Called Delete operation sCalled
4Delete operotlom
pop operatn
Decseue operoatlon
there is a
In Stauck There ib
no uastage |S In Cueue
S Space.
of
o f memor'y Spoce. wouloge of memory
6plate Counter at Masmuge 4Students Stcmdng i'n a hihe at
ReCeption i'san Exo mple of Stack fees Countes i
an
&rample of
aueue.
Diffesende betuween Singly omd Doubly inked Li'p4 62
uLLLLIIZILLUuIILILUILllitiniLiLLILIGmITTIu nIIILULLTIIITZ
Singly Linked Lis4 doubly Linked Li'st
1 Singly Linke& List has nocls L Doubly uked LiBt hos nodes
with data fied Cmd next
Link with data fteld omd tuwo
field (foruward link) pornterfield.( Backwerd ond
& forwerd Link)
Dato yt & revicws Doia Next
2I allows trauersal only I+ allow a two way
+sersal.
3 T eqpires ome L poiter3 I t rqures two Li's+ pornder
Variable (Star+ amd Lan)
variable (Start)
4 I + OCCupres Le83 memory I+ oCCUpIes more memory
S Complexity of Ingertiom amd S Complexity of Irertion owd
Deletion a4 known
POitom Deletiom at known posdiom
On) O1).
((%s
Dfferene betuween Lintar omd Non-intar data Struchre
LinecAY data Structure Non-Linaor dato Sructure
1 Tn 4h'h dota S4ructure|1In this data Stsucture
The elemuntsare orgonied data t's organized witheu
t'n a
quunce Such as Oy Secuece.
6 Aray, Stack, queuee& Tree, Groph etc.
2In Lintar datu Structurej In non-Linaar D.S
Single Le i involued.multple Leves are invohed,
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.
6 ApeliCatorsof Linar |6 APplicatons of non-
D.S are mainy in Linaar D.S are in
APplicathon Software AyHicia Intelligece
developmaw Ome image proteAing.
Diffexence betuween Array Omd Linked Li'34 63
ZUITLILTLLLIIZTIUTUTTUU TTiTUTTZITIzIITIIzuLz
ATsay Linked-upt
tixed LSize of a Lit 's not fixed
1 Sze of a n Aray i
2 Aray a Collection
of a Liwked-Li's+ is a Collecdion o
Homogenesus (Similardala type node Cdata 2 addres)
froom
alloCate trom 3Memory allocoated
3Memory
Stack.
heoP
i+h S4atic 4Liwked-Lit work wi'th
4Aray work
bymamie data Strueture.
data Structure .
a r e Stored i'n
5 Elemanks 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.
3»There will no+
3 These Can hee
be amy Cycle/Lops. loops/Cycle.
4Repreenta datoa in 4 Represents dada Simihr
The form ofa tree Strutue +o a utuwork.
in a ht'erarehital manneY
S In raph n e or more
SIn +ree my o n path betuween
Pa+h between two nosestham on
two nedes.
Zn this Preorder, In +hu's 8FS md
In order Cmd Aostorder
TraeTbal. OFSouersal.
Ex &9

You might also like