Ds Unit4
Ds Unit4
Tree w a
a hierachi Cal
noninean data sbucture & epresent
Cg ReCovds, famity
elatiomshu
hee,Takles of
between Data elemorts .
Cortertta.
BASIC
Keot :TERMINOLOaY:
Re ias firt in the
fierachical mongemunt
0f data items. h tiy. A s tko Rovt tem
Node: Each data tem un a bee us Call ed Node..
t shecifies -tfe
data 'nformation & Links, to
OtR dorta tems. Here A8,c, 0,€. are Nodes
Veee of A node : st the nwnben of
subtrees
Node A s3, node in a given hee.In tke fiy-
of a
dagree ot
(A)- Rovt
Edge Level o
(D) Level 1
(H) Level 2
) ) Level 3
Tree
ARovt Node)
Sleft SuccessY
0f A oY
Left SubTe
Right Subhee
E
Bmay Tree
% 6 left succeSsaY
s &C is Sigtsucces or of Noe A .
Anynode N na
binay Tee has eitker o,L or 2 sucCANOYA.
The nodes wHh no suCCAs or) Called Terminal Nodes?
ALGGEBRAC EXPRESSIONS :
E= a-b)/ (c*a)+e)
Above epeson E Con be cpesented by means of
-tke binaoty Tree as-(inaling ondy bimary opeatio
a b
C d
COMPLETE BINARY TREE:
A Tree us said tobe =
a Comhete
(f al its levels
TreebmoTy
except possiby tte last, have t
Maoimum numben 0f PoBsIble nodes. 1e. Level
C4 Bree Can Rave t mot 2n nodes. y n ottar
Wrds f tere au m nodes ct Lerel then
Tree
Contans atmost Qm nodes at Lerel .
(6
Jn Complete Bnaty Tee,childen &
Chy hde KK.be Pasy
farent f
Rateyminid as
The Lefl & ight chidd o4 node K au hodes
B*K|A +1], JUspectely.& tee Perent of
nole tk u te node [K½.
8 The Qerte (0,) of a Complete Ginooy Tiree (T)
LSHE n node given by
n
oite To childen
Called-Gaternalnodes
Called - temal nodes
fg. Circlesed
for jnternal
nodes teeal
Seuwu ()used for external
nodes.
(- Bina Toee.
e Conetted into . Lateded.2B
So
hancd
tn TREE [2*K+].
I{ TREE [I= NULL, Undicates tie Tree s emphy.
45
5)
30
15
(30 Q5
R5 3
*)Reyre 4 iS
(K wually
apfroimately 2d+l elementa.
Ineficient mehod
as stted above eason.
cficient for Complete
&inany Tree or Newey
to Complce.
The lrguol sefrasevdotisn ya node in c is ien elas
Struet ade;
Chou dodo;
nde *Retild
Hrut node child;
Sut
Gedet atzuct nade
s.folRo:
(a) INfo fk? Cotai-ee dat atte hode N.
b) LEf T [k CotùnyA location of te Lett childof Nodan
C) RIGHT [K? ontoainy t loCatim o t iyhi childoNadeN,
fonten
Any subtbee s empty ten tee Conesfonding
Root R.
+5 45
4 30 7
AVAlL 25
77
|3
88
90
12
13
12
14
E H
k
L
fost
ovden:
AO
to
6 HO
Inorde:
Do
Lo
HEADER NODES: -A speci al node s added to
x|K
Al
K
(One twoy Threading)
n TWo LWay Thecding ot ree,atfead o aUso
(h-the LEFT fietd od node & oiQe point to The Pecedino
node n
the inorde aveal of Tree.
[A
D
Tiwo- way inordenThveading)
The Left Pon ter of tee firt
node & the ignt Pointey
Oftthe tast node il
Contuin tee nuee'yaliie
when Tree does not have a headen node, but ie
foint to tte keaden node when T does fave a tndenod
HEADER NODE
LAl
YD
(Tuo-ytireading wHG
headen node)
HUFFMAN'S AL(oORITHM:
In any Q-Tree tfe nnben ot eterncl nodes (NE)
uOne more t6an te nunben o iternal nodes"le.
NE = Nyt1)
Heve Ni= 6
NE = 6+L
LI= 0+l+|+2+3+2=9
Here
LI 2n= 9+Q.6=9t 12 =1=Le
+
fomula: LE = L +2n
whese n-inteynal nodes tue
s frany-Tee.
Let T Us a a- Tree LoiH n- exterhe nodes Å subþohl
tRe extevnal nodes iy asined a (hoh
gative)
Coch c
lengts. te.
+ Wnn
P=WtWyly t
here wi= ueight Of n external hode
li= fate length of an etevnl node.
P=2.2+3.2+ 5.2+11-2 = 42
P =-2+3-3t 5-3 t 2.1
2] 3 = 23+3.3 +5-2.+ I1-1 =36.
LC) T3
Huffmon
Aloonthim: Hutfman
de fined in tem, of Algoithim us recUs
vely
the numbN Of
tRe solution for one Lseijht weights and
One node. On tthe
Jy smply hree wit he
otfn hond Hufman alqorthm
Constucting te tec fom the bottom up
tion fom the the
toh don.
Mutman olganithm gensoted a aiabl
Jength cade in A a cy
Hot hughen
efesen ded higharno.
d hids.tere he ymbal
cortucked de
is
weighta
Wt W2,W3, -
la)
(6)
(c)
(d)
(2)
Ie) (-f)
3
(12)
l)
(-k)(FmaTree)
To imhlemnt the
Hutfman algoitGm,oe
A AMay wT to holdthe eights Yeyure an
of nodeS. 1:e Tree
martained by fow Poarllel
INFO, LEFT, RI Arags,
GHTAWJT.
INFo
E) The abone Tree Jubresnted n mmry as
WT LEFT RiGHT INFO
1
A 22 LEPT RIGHT
2 5 1
A 22
3 C
C
5 oo
19 )
2 D
6
7
2
. Q5 ooooo
6 ooo
8 H 5 o oooooo 7
H 5
lo
J2
5 2
22 6 3
oo
13
31
44 4
J6
56
106
|2
)3
AVAn =9 14
Matin a
5,
RooT=1
AVAIL=6
minfeab, ohee
& each node
te
locrtion cfthe olooi of aClnt Contaby
subtree.
wt
5TEPS: GO Remove tee node N5]&
estion)
Ng
-watien
=(5,2] boy
. the
C-0||
Hence Code Ae
A: o0
C:o| O: I
E: llolo f: 6lo h: lo H: l160