DS CH-6 (Final ?)
DS CH-6 (Final ?)
STRUCTURES
USING C
REEMA THAREJA
Q
Chapter6
CHAPTER-6
Taee S
(D
(
Teee
Terminolo9y oP tree
Root a hee
c e IS Called
The topmost node of
Roo+
(A) Root
(8
A 7 Root in tee
l e a f Node - The
The abt node oF each Pah )
extenal node.
an Called caP mode
(A
B
(
eaf node
Node
Node
(D
A Node
Edge
Node
5) Forest
A Collec tion di'soint tree
is Called a8 Fo xest
(A
D
APlo movinq node CPoves+).
(D
6) Child nod, -
Chld ofA
Child
of B
Sibling
Sibling
tree
- Levelo
-Level
Level2
Deqec of node
The To tal Numbe of
Childhen OP hode S Ca led deqe ch
node
Deg oR 8 2
Degree oF C =2
8
Branch:
The bath ending Ith leaf
mode s Called brarch
EX.
A Heigh o Tee
4 CA8, D, H)
.8,0,T)
(0
Degenden ts
Ancesto
Desccndent of 8IS
Ancesto oF E S B andA
D, E Qnd H
19) Path:
The Seguen ce of Nodes and edges
hom Ohc node anotheh nod u
Called as Pa th.
Path 8/ + to Z iS
A-8 0 -I
Subtrce -
Any hode oF he tet a lon g
wIth descendant 1S Calld Subthee
Bn
Chit
mode
TD
(
().
(D
b) Complete Binahy ttt-
The 8inay ee
om he left
Ex. (A
B
D
Peropenhes of 8inay te
No. oF hodes 1h Binahy
The maxi mum
Lve Level 2
2-
G)Level3
2 3
3 23-
maximy m No. Of hodes at level h
The
Binay Tce OP eve is 22
No. oF
Level pehty max
Lerel Nodes at
eve
Level 2 2-1
22-
Level 3-(O)
3 23-
(
HI
HI
t HpHBEn ta hon -
Linked
In data value
LLink nRight Link Stee add css
of LeP+
Subtee
RLink Stee addxss
of Right
Subtee
Pc ordo
a) Visit oot node
b) Vistt all the node n the }ePt
Subtrce
Vis+ all he node n the
ght
Sybtae,
Root
Ex
Preo&de A
Root
LePt Righ+
Subtce Subtree
hcodch> A 8, D,F, C, P,C
End iF
STEP 2: SET PTR:=Roo T
OnSnorda
the node Ih LeP Subtee
a) VISI+ all
b) VISI+oot nede
Left Subte
(B
) ght
(D Sub ter
gnorden B (A
Root
Lept Rght
Subhee Subtce
A Root
Sub
Past oden
RoOt
LePt Su bhe
L Rght
Sub tae
Post 0deh D,E, B, F, Cn, C, A
STEP:- 9F CRo0T =
NULL,THEN
RETURN
tEND IP]
STEP 2:- SET PTR: RooT =
STEP3:
PoSTORDER ( PTR -9 LCHILD)
STEP 4 -
poS T ORDER PTR>RCHILO)
STEP5: PRINT PTR DATA
STEP6: END
nor der, posto>d Ond P)cosdeh
tayOnSal Of h Rllouolh9 thee:
7Root
SoM (A
Let
Right Subhee
Subhee
a) Pre ordn-
Root
Lept Right
Subhee Subtrtc
Prcoyde A,B,EECe
b) Ino do -
Root
LePt Right
Sube Subhce
LePt Root
Riyht
Subthec Syhhe
(8
(D
(
(go
95
pehtes
Al ho de he leP+ Subtree
esse
2) hode of the
Rght Subtrce ae
geatty
LePt 2 Righ+ Subtree ae also Binay
Seahch
Jnsehon
delehon
Seahchin9
Insehon:- The Yo cess n which 9nsert 0
node 1h Bina y Seanch 7ee S Caled
Jnsenhon
Syppose 55 Ins ert n ee
(5o
(22 ( 60
1 3
STEP1- Compahe he 55 with oot 50
S5 >5o
Move Rht chilc of oot.
STEP2:-Compase 55 h 6o
55 60 Ce
Move Let chil Df pot
STEP3: ComPane 55 oh 3 o
55>3 o
Move Right child of oot.
(60
gon h m: INS 8ST (RooT, ITEn)
ohene Roo Is boin tu Vaiable
ELSE
xetun Scanch Coot> Right, Item)
END IP
STEP2 END
peletion: a Pocess which
Deletion S
Scanch tee
ddeh the node n Bi ncy
is Called delehion.
(s) (15
Delete (18 (
(1o (20
Case 8 (12
8
APt
Befoe Delek
delee
hode hod
delek (25)
Ca_e 2
(19 (3
(15)
Dekte (2
Applicaton of tree.
Set >cptsenta tion
9+ S used fo
2) Tee is In decision ma Hing
gntensting applicohon oF e S playing
gomes
games ke chess, chec Ken S, hc-4ac-toe ete