SlideShare a Scribd company logo
1 of 16
Download to read offline
9.1 INTRODUCTION
A B, C D
A
9.1.1 Basic Terminology
Root node R R = NULL
Sub-trees R NULL T1
, T2
, T3
R
Leaf node
Path path.
A I A, D I
Ancestor node
A, C G
K
LeaRNINg OBjeCTIve
So far, we have discussed linear data structures such as arrays, strings, stacks,
and queues. In this chapter, we will learn about a non-linear data structure called
tree. A tree is a structure which is mainly used to store data that is hierarchical in
manipulate arithmetic expressions, construct symbol tables, and for syntax analysis.
Trees
chapTer 9
280 Data Structures Using C
Descendant node A
C, G, J K A
Level number level number
level number + 1
Degree
In-degree
Out-degree
9.2 TYPeS OF TReeS
9.2.1 general Trees
9.2.2 Forests
B
E F H I
D
A
T1
Root node
G
KJ
C
T3
T2
Figure 9.1
Trees 281
9.2.3 Binary Trees
'root' root = NULL
R T1
T2
R T1
R T2
R
Terminology
Parent N T left successor S1
right successor S2
N parent S1
S2
S1
S2
N
Level number level
number
parent's level number + 1
Degree of a node
Sibling
siblings
Root node
2
4 5 6 7
12111098
3
1
T1 T2
Figure 9.3 Binary tree
B
F
E
A
D
H
CB
F G
E
D
H
C
(a) (b)
G
Figure 9.2 Forest and its corresponding tree
2
4 5 6 7
12111098
3
1
Root node
(Level 0)
(Level 1)
(Level 2)
(Level 3)
Figure 9.4 Levels in binary tree
282 Data Structures Using C
Leaf node
Similar binary trees T T¢
similar binary trees
Copies T T¢ copies
T¢ T
Edge N
n n – 1
Path .
Depth depth N
R N
Height of a tree
h h 2h
– 1
h 2h
– 1
n log2
(n+1) n.
In-degree/out-degree of a node
out-degree
Complete Binary Trees
A complete binary tree
Tn
n r T 2r
20
= 1 21
= 2 22
= 4
6 23
= 8
T13
K
2 × K
2 × K + 1
4 8 (2 × 4) 9 (2 × 4 + 1)
K | K/2 |
4 | 4/2 | = 2
Tn
Hn
= | log2
(n + 1) |
E
A
CB
D
Tree T Tree T¢
J
F
HG
I
Figure 9.5 Similar binary
trees
ED
A
CB
Tree T Tree T¢
ED
A
CB
Figure 9.6 ¢ is a copy
1
2 3
4 5 6 7
8 9 10 11 12 13
Figure 9.7 Complete binary tree
Trees 283
T
Extended Binary Trees
T
internal nodes external
nodes
Representation of Binary Trees in the Memory
Linked representation of binary trees
struct node {
struct node *left;
int data;
struct node *right;
};
ROOT
ROOT = NULL
X NULL
1
2 3
4 5 6 7
X 8 9 10 12X X X X X X XX X11
X X X
Figure 9.9 Linked representation of a binary tree
(a) (b)
Figure 9.8 (a) Binary tree and (b) extended
binary tree
284 Data Structures Using C
2
4 5 6 7
12111098
3
1
LEFT DATA RIGHT
–1
–1
–1
5
9
20
1
–1
–1
–1
–1
–1
2
8
10
1
2
3
4
7
9
5
11
12
6
–1
–1
–1
18
12
14
8
–1
–1
16
ROOT
3
AVAIL
15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
11
Figure 9.10 Binary tree T Figure 9.11 Linked representation of binary tree T
example 9.1
Solution
LEFT NAMES RIGHT
12
9
19
1
–1
–1
6
–1
–1
–1
11
–1
13
17
–1
–1
–1
20
–1
–1
–1
15
ROOT
3
AVAIL
7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Pallav
Amar
Deepak
Janak
Kuvam
Rudraksh
Raj
Kunsh
Tanush
Ridhiman
Sanjay
Pallav
Amar
Deepak
Janak
KuvamRudraksh
Raj
KunshTanushRidhiman
Sanjay
Trees 285
Sequential representation of binary trees
∑ TREE
∑
is, TREE[1]
∑ K
(2 × K) (2 × K+1)
∑ TREE (2h
–1)
h height
∑ NULL TREE[1]
= NULL
9.2.4 Binary Search Trees
A
9.2.5 expression Trees
Exp = (a – b) + (c * d)
example 9.2 Exp = ((a + b) – (c * d)) % ((e ^f) / (g – h))
Solution
%
+ ^ –
a b c d f g h i
–
Expression tree
/
example 9.3
Solution
%/
+
^
–
a b c d f g h i
/
20
15
12 17
16 18
35
21 39
36 45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
20
15
35
21
39
16
18
12
17
36
45
Figure 9.12 Binary tree and its sequential
representation
+
a b c d
Figure 9.13 Expression tree
286 Data Structures Using C
[{(a/b) + (c*d)} ^ {(f % g)/(h – i)}]
example 9.4 Exp = a + b / c * d – e
Solution
Exp = ((a + ((b/c) * d)) – e)
9.2.6 Tournament Trees
n
selection tree
winner trees
loser tree
a, b, c, d, e, f, g h a b c d e
f g h
a, d, e
a e
a
9.3 CReaTINg a BINaRY TRee FROm a geNeRaL TRee
Rule 1:
Rule 2:
Rule 3:
example 9.5
+
/
a
b c
d
–
e
Expression tree
a b c d e f g h
a
a
a d e
e
g
Figure 9.14
B
E F I J
D
A
K
G H
C
Trees 287
Step 1: A
Step 2: A A
A A A
Step 3: B B is E C
Step 4: C C is F D
Step 5: D D is I
D
Step 6: I I I
I J
I
Step 7: J J is K
J
DF
B
CE
A
DF
B
CE
A
I
DF
B
CE
A
I
J
DF
B
CE
A
I
J
K K
B
CE
A
DF
IG
H J
Step 8: E, F, G, H, K
9.4 TRaveRSINg a BINaRY TRee
9.4.1 Pre-order Traversal
A
A
B
B
CE
A
B C
A
Figure 9.15 Binary tree
288 Data Structures Using C
A, B, C
depth-first traversal
+ – a b * c d (from Fig. 9.13)
% – + a b * c d / ^ e f – g h (from Fig of Example 9.2)
^ + / a b * c d / % f g – h i (from Fig of Example 9.3)
example 9.6
Solution
TRAVERSAL ORDER: A, B, D, G, H, L, E, C, F, I, J,
and K
TRAVERSAL ORDER: A, B, D, C, D, E, F, G, H, and I
9.4.2 In-order Traversal
B, A C
symmetric traversal
Step 1: Repeat Steps 2 to 4 while TREE != NULL
Step 2: Write TREE DATA
Step 3: PREORDER(TREE LEFT)
Step 4: PREORDER(TREE RIGHT)
[END OF LOOP]
Step 5: END
->
->
->
Figure 9.16 Algorithm for pre-order traversal
Step 1: Repeat Steps 2 to 4 while TREE != NULL
Step 2: INORDER(TREE LEFT)
Step 3: Write TREE DATA
Step 4: INORDER(TREE RIGHT)
[END OF LOOP]
Step 5: END
->
->
->
Figure 9.17 Algorithm for in-order traversal
A
B C
D E F
G H I J
KL
G
H I
B C
D E
F
A
(a) (b)
Trees 289
example 9.7
TRAVERSAL ORDER: G, D, H, L, B, E, A, C, I, F, K, and J
TRAVERSAL ORDER: B, D, A, E, H, G, I, F, and C
9.4.3 Post-order Traversal
B, C,
A
LRN
example 9.8
TRAVERSAL ORDER: G, L, H, D, E, B, I, K, J, F, C, and A
TRAVERSAL ORDER: D, B, H, I, G, F, E, C, and A
9.4.4 Level-order Traversal
breadth-first traversal algorithm
TRAVERSAL ORDER:
A, B, C, D, E, F, G, H, I, J, L, and K
(b)(a)
TRAVERSAL ORDER:
A, B, and C
TRAVERSAL ORDER:
A, B, C, D, E, F, G, H, and I
(c)
A
CB
HG
B
ED
L
JI
C
F
K
A
B
D
G
C
F
A
E
IH
Figure 9.19 Binary trees
Step 1: Repeat Steps 2 to 4 while TREE != NULL
Step 2: POSTORDER(TREE LEFT)
Step 3: POSTORDER(TREE RIGHT)
Step 4: Write TREE DATA
[END OF LOOP]
Step 5: END
->
->
->
Figure 9.18 Algorithm for post-order traversal
290 Data Structures Using C
9.4.5 Constructing a Binary Tree from Traversal Results
In–order Traversal: D B E A F C G Pre–order Traversal: A B D E C F G
Step 1
Step 2
Step 3
A
DBHE FJCG
A
DBHE C
IF G
A
DBHE C
F G
I
A
B
D F G
J
HEI
A
B C
D E
H
I J
I I
C
Figure 9.21 Steps to show binary tree
9.5 HUFFmaN’S TRee
'0'
A
DBE FCG
D E
A
B FCG
A
B C
D E F G
Figure 9.20
Trees 291
'1'
n n – 1
external path length
internal path length
LI
= 0 + 1 + 2 + 1 + 2 + 3 + 3 = 12
LE
= 2 + 3 + 3 + 2 + 4 + 4 + 4 + 4 = 26
LI
+ 2 * n = 12 + 2 * 7 = 12 + 14 = 26 = LE
LI
+ 2n = LE
n n
P
P = W1
L1
+ W2
L2
+ …. + Wn
Ln
Wi
Li
Ni
example 9.9 T1
, T2
T3
5 2
2 3 11 5
2
3 4
5 7 5
2 3
11
T1 T2 T3
Binary tree
Solution
T1
P1
= 2◊3 + 3◊3 + 5◊2 + 11◊3 + 5◊3 + 2◊2 = 6 + 9 + 10 + 33 + 15 + 4 = 77
T2
P2
= 5◊2 + 7◊2 + 3◊3 + 4◊3 + 2◊2 = 10 + 14 + 9 + 12 + 4 = 49
T3
P3
= 2◊3 + 3◊3 + 5◊2 + 11◊1 = 6 + 9 + 10 + 11 = 36
Technique
n
Figure 9.22 Binary tree
292 Data Structures Using C
Step 1: Create a leaf node for each character. Add the character and its weight or frequency
of occurrence to the priority queue.
Step 2: Repeat Steps 3 to 5 while the total number of nodes in the queue is greater than 1.
Step 3: Remove two nodes that have the lowest weight (or highest priority).
Step 4: Create a new internal node by merging these two nodes as children and with weight
equal to the sum of the two nodes' weights.
Step 5: Add the newly created node to the queue.
Figure 9.23 Huffman algorithm
example 9.10
A
7
B
9
C
11
D
14
E
18
F
21
G
27
H
29
I
35
J
40
C
11
D
14
E
18
F
21
G
27
H
29
I
35
J
40
16
A
7
B
9
25
A
7
B
9
16
A
7
B
9
C
11
D
14
E
18
F
21
G
27
H
29
I
35
J
40
25
F
21
G
27
H
29
I
35
J
40
E
18
C
11
D
14
16
34
C
11
D
14
25
46
F
21
G
27
H
29
I
35
J
40
E
18
16
34
A
7
B
9
Trees 293
86
25
46 J
40
C D
F
21
56
G
27
H
29
I
35
69
E16
34
125
211
11 1418
A
7
B
9
5646
I
35
J
40
34
J
40
46 56 69
A
7
B
9
8656 69
86
25
46 J
40
C
11
D
14
F
21
56
G
27
H
29
I
35
69
E
18
A
7
B
9
16
34
125
25
46 J
40
G
27
H
29
C
11
D
14
F
21
I
35
E
18
A
7
B
9
16
34
25 G
27
H
29
C
11
D
14
I
35
E
18
16
34F
21
C
11
D
14
25 F
21
G
27
H
29
E
18
16
A
7
B
9
294 Data Structures Using C
Data Coding
r 2r
r=1
A B
B
r=2 r=3
ABBBBBBAAAACDEFGGGGH
000001001001001001001000000000000010011100101110110110110111
a, e,
i r w, x, y, z
A, E, R, W, X, Y,
Z
A E R
X Y W Z
0 1
0 1
0 0
0
0
1 1
1
1
Figure 9.24 Huffman tree
9.6 aPPLICaTIONS OF TReeS
∑
Table 9.3 Characters with their codes
Character Code
A 00
E 01
R 11
W 1010
X 1000
Y 1001
Z 1011
Table 9.1 Range of characters that
can be coded using r = 2
Code Character
00 A
01 B
10 C
11 D
Table 9.2 Range of characters that
can be coded using r = 3
Code Character
000 A
001 B
010 C
011 D
100 E
101 F
110 G
111 H

More Related Content

What's hot

Appendex f
Appendex fAppendex f
Appendex fswavicky
 
Logarithms
LogarithmsLogarithms
Logarithmssupoteta
 
Massively distributed environments and closed itemset mining
Massively distributed environments and closed itemset miningMassively distributed environments and closed itemset mining
Massively distributed environments and closed itemset miningMehdi Zitouni
 
20130108 ast signature based boolean matching in the presence of don’t cares_...
20130108 ast signature based boolean matching in the presence of don’t cares_...20130108 ast signature based boolean matching in the presence of don’t cares_...
20130108 ast signature based boolean matching in the presence of don’t cares_...Hanson Chi
 
Data made out of functions
Data made out of functionsData made out of functions
Data made out of functionskenbot
 
AP PGECET Computer Science 2016 question paper
AP PGECET Computer Science 2016 question paperAP PGECET Computer Science 2016 question paper
AP PGECET Computer Science 2016 question paperEneutron
 
Review session2
Review session2Review session2
Review session2NEEDY12345
 
FUNCTION- Algebraic Function
FUNCTION- Algebraic FunctionFUNCTION- Algebraic Function
FUNCTION- Algebraic FunctionJanak Singh saud
 
Ee693 questionshomework
Ee693 questionshomeworkEe693 questionshomework
Ee693 questionshomeworkGopi Saiteja
 
Directed Acyclic Graph
Directed Acyclic Graph Directed Acyclic Graph
Directed Acyclic Graph AJAL A J
 
Week 8 (trees)
Week 8 (trees)Week 8 (trees)
Week 8 (trees)amna izzat
 
Digital Logic Design-Lecture 5
Digital Logic Design-Lecture 5Digital Logic Design-Lecture 5
Digital Logic Design-Lecture 5Samia Sultana
 

What's hot (20)

Appendex f
Appendex fAppendex f
Appendex f
 
Logarithms
LogarithmsLogarithms
Logarithms
 
Massively distributed environments and closed itemset mining
Massively distributed environments and closed itemset miningMassively distributed environments and closed itemset mining
Massively distributed environments and closed itemset mining
 
20130108 ast signature based boolean matching in the presence of don’t cares_...
20130108 ast signature based boolean matching in the presence of don’t cares_...20130108 ast signature based boolean matching in the presence of don’t cares_...
20130108 ast signature based boolean matching in the presence of don’t cares_...
 
Data made out of functions
Data made out of functionsData made out of functions
Data made out of functions
 
Gate-Cs 1996
Gate-Cs 1996Gate-Cs 1996
Gate-Cs 1996
 
INVERSE FUNCTION
INVERSE FUNCTIONINVERSE FUNCTION
INVERSE FUNCTION
 
K map
K mapK map
K map
 
Lec15
Lec15Lec15
Lec15
 
presentation about set theorem
presentation about set theorempresentation about set theorem
presentation about set theorem
 
AP PGECET Computer Science 2016 question paper
AP PGECET Computer Science 2016 question paperAP PGECET Computer Science 2016 question paper
AP PGECET Computer Science 2016 question paper
 
Review session2
Review session2Review session2
Review session2
 
Chapter 22 Finite Field
Chapter 22 Finite FieldChapter 22 Finite Field
Chapter 22 Finite Field
 
FUNCTION- Algebraic Function
FUNCTION- Algebraic FunctionFUNCTION- Algebraic Function
FUNCTION- Algebraic Function
 
K - Map
  K - Map    K - Map
K - Map
 
Ee693 questionshomework
Ee693 questionshomeworkEe693 questionshomework
Ee693 questionshomework
 
Directed Acyclic Graph
Directed Acyclic Graph Directed Acyclic Graph
Directed Acyclic Graph
 
Week 8 (trees)
Week 8 (trees)Week 8 (trees)
Week 8 (trees)
 
UNIT .01
UNIT .01UNIT .01
UNIT .01
 
Digital Logic Design-Lecture 5
Digital Logic Design-Lecture 5Digital Logic Design-Lecture 5
Digital Logic Design-Lecture 5
 

Similar to Chapter 09-Trees

ds 10-Binary Tree.ppt
ds 10-Binary Tree.pptds 10-Binary Tree.ppt
ds 10-Binary Tree.pptkhitishlpu
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeManishPrajapati78
 
chapter5.PPT
chapter5.PPTchapter5.PPT
chapter5.PPTSaralaT3
 
Project matlab group one,dzaklo courage kwasi
Project matlab group one,dzaklo courage kwasiProject matlab group one,dzaklo courage kwasi
Project matlab group one,dzaklo courage kwasiKNUST
 
Notes and Formulae Mathematics SPM
Notes and Formulae Mathematics SPM Notes and Formulae Mathematics SPM
Notes and Formulae Mathematics SPM Zhang Ewe
 
Notes and-formulae-mathematics
Notes and-formulae-mathematicsNotes and-formulae-mathematics
Notes and-formulae-mathematicsAh Ching
 
Ramco Sample Paper 2003
Ramco  Sample  Paper 2003Ramco  Sample  Paper 2003
Ramco Sample Paper 2003ncct
 
Map reduce and the art of Thinking Parallel - Dr. Shailesh Kumar
Map reduce and the art of Thinking Parallel   - Dr. Shailesh KumarMap reduce and the art of Thinking Parallel   - Dr. Shailesh Kumar
Map reduce and the art of Thinking Parallel - Dr. Shailesh KumarHyderabad Scalability Meetup
 
Developer Intro Deck-PowerPoint - Download for Speaker Notes
Developer Intro Deck-PowerPoint - Download for Speaker NotesDeveloper Intro Deck-PowerPoint - Download for Speaker Notes
Developer Intro Deck-PowerPoint - Download for Speaker NotesMax De Marzi
 
DS MCQS.pptx
DS MCQS.pptxDS MCQS.pptx
DS MCQS.pptxBoomijaIT
 
KARNAUGH MAP(K-MAP)
KARNAUGH MAP(K-MAP)KARNAUGH MAP(K-MAP)
KARNAUGH MAP(K-MAP)mihir jain
 
Fileprocessing lec-7
Fileprocessing lec-7Fileprocessing lec-7
Fileprocessing lec-7sawsan slii
 

Similar to Chapter 09-Trees (20)

ds 10-Binary Tree.ppt
ds 10-Binary Tree.pptds 10-Binary Tree.ppt
ds 10-Binary Tree.ppt
 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
 
3rd Semester Computer Science and Engineering (ACU-2022) Question papers
3rd Semester Computer Science and Engineering  (ACU-2022) Question papers3rd Semester Computer Science and Engineering  (ACU-2022) Question papers
3rd Semester Computer Science and Engineering (ACU-2022) Question papers
 
chapter5.PPT
chapter5.PPTchapter5.PPT
chapter5.PPT
 
Project matlab group one,dzaklo courage kwasi
Project matlab group one,dzaklo courage kwasiProject matlab group one,dzaklo courage kwasi
Project matlab group one,dzaklo courage kwasi
 
3rd Semester Computer Science and Engineering (ACU) Question papers
3rd Semester Computer Science and Engineering  (ACU) Question papers3rd Semester Computer Science and Engineering  (ACU) Question papers
3rd Semester Computer Science and Engineering (ACU) Question papers
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Notes and Formulae Mathematics SPM
Notes and Formulae Mathematics SPM Notes and Formulae Mathematics SPM
Notes and Formulae Mathematics SPM
 
Notes and-formulae-mathematics
Notes and-formulae-mathematicsNotes and-formulae-mathematics
Notes and-formulae-mathematics
 
Mathematics formulas
Mathematics formulasMathematics formulas
Mathematics formulas
 
Ramco Sample Paper 2003
Ramco  Sample  Paper 2003Ramco  Sample  Paper 2003
Ramco Sample Paper 2003
 
Adobe
AdobeAdobe
Adobe
 
Ai4 heuristic2
Ai4 heuristic2Ai4 heuristic2
Ai4 heuristic2
 
Map reduce and the art of Thinking Parallel - Dr. Shailesh Kumar
Map reduce and the art of Thinking Parallel   - Dr. Shailesh KumarMap reduce and the art of Thinking Parallel   - Dr. Shailesh Kumar
Map reduce and the art of Thinking Parallel - Dr. Shailesh Kumar
 
Rumus matematik examonline spa
Rumus matematik examonline spaRumus matematik examonline spa
Rumus matematik examonline spa
 
Developer Intro Deck-PowerPoint - Download for Speaker Notes
Developer Intro Deck-PowerPoint - Download for Speaker NotesDeveloper Intro Deck-PowerPoint - Download for Speaker Notes
Developer Intro Deck-PowerPoint - Download for Speaker Notes
 
Compiler Design Unit 3
Compiler Design Unit 3Compiler Design Unit 3
Compiler Design Unit 3
 
DS MCQS.pptx
DS MCQS.pptxDS MCQS.pptx
DS MCQS.pptx
 
KARNAUGH MAP(K-MAP)
KARNAUGH MAP(K-MAP)KARNAUGH MAP(K-MAP)
KARNAUGH MAP(K-MAP)
 
Fileprocessing lec-7
Fileprocessing lec-7Fileprocessing lec-7
Fileprocessing lec-7
 

More from MuhammadBakri13

More from MuhammadBakri13 (12)

Uxd01 uxd fundamental
Uxd01 uxd fundamentalUxd01 uxd fundamental
Uxd01 uxd fundamental
 
Chapter 4 stack and queue
Chapter 4 stack and queueChapter 4 stack and queue
Chapter 4 stack and queue
 
Views in MySQL
Views in MySQLViews in MySQL
Views in MySQL
 
Slide 03: Data Management
Slide 03: Data ManagementSlide 03: Data Management
Slide 03: Data Management
 
Chapter 02 - Database Development
Chapter 02 - Database DevelopmentChapter 02 - Database Development
Chapter 02 - Database Development
 
Slide 01-Data and the Enterprise
Slide 01-Data and the EnterpriseSlide 01-Data and the Enterprise
Slide 01-Data and the Enterprise
 
Chapter 14 Searching and Sorting
Chapter 14 Searching and SortingChapter 14 Searching and Sorting
Chapter 14 Searching and Sorting
 
Python Objects
Python ObjectsPython Objects
Python Objects
 
Looping
LoopingLooping
Looping
 
Conditional Statements
Conditional StatementsConditional Statements
Conditional Statements
 
Function
FunctionFunction
Function
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 

Recently uploaded

VIP Model Call Girls Chakan ( Pune ) Call ON 8005736733 Starting From 5K to 2...
VIP Model Call Girls Chakan ( Pune ) Call ON 8005736733 Starting From 5K to 2...VIP Model Call Girls Chakan ( Pune ) Call ON 8005736733 Starting From 5K to 2...
VIP Model Call Girls Chakan ( Pune ) Call ON 8005736733 Starting From 5K to 2...SUHANI PANDEY
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 8005736733 Starting From 5K to...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 8005736733 Starting From 5K to...VIP Model Call Girls Hadapsar ( Pune ) Call ON 8005736733 Starting From 5K to...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 8005736733 Starting From 5K to...SUHANI PANDEY
 
Hot Call Girls 🫤 Malviya Nagar ➡️ 9711199171 ➡️ Delhi 🫦 Whatsapp Number
Hot Call Girls 🫤 Malviya Nagar ➡️ 9711199171 ➡️ Delhi 🫦 Whatsapp NumberHot Call Girls 🫤 Malviya Nagar ➡️ 9711199171 ➡️ Delhi 🫦 Whatsapp Number
Hot Call Girls 🫤 Malviya Nagar ➡️ 9711199171 ➡️ Delhi 🫦 Whatsapp Numberkumarajju5765
 
Kondhwa ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Kondhwa ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Kondhwa ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Kondhwa ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Get Premium Hoskote Call Girls (8005736733) 24x7 Rate 15999 with A/c Room Cas...
Get Premium Hoskote Call Girls (8005736733) 24x7 Rate 15999 with A/c Room Cas...Get Premium Hoskote Call Girls (8005736733) 24x7 Rate 15999 with A/c Room Cas...
Get Premium Hoskote Call Girls (8005736733) 24x7 Rate 15999 with A/c Room Cas...MOHANI PANDEY
 
Hot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night Standkumarajju5765
 
DENR EPR Law Compliance Updates April 2024
DENR EPR Law Compliance Updates April 2024DENR EPR Law Compliance Updates April 2024
DENR EPR Law Compliance Updates April 2024itadmin50
 
Call Now ☎ Russian Call Girls Connaught Place @ 9899900591 # Russian Escorts ...
Call Now ☎ Russian Call Girls Connaught Place @ 9899900591 # Russian Escorts ...Call Now ☎ Russian Call Girls Connaught Place @ 9899900591 # Russian Escorts ...
Call Now ☎ Russian Call Girls Connaught Place @ 9899900591 # Russian Escorts ...kauryashika82
 
Call Girls Magarpatta Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Magarpatta Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Magarpatta Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Magarpatta Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Contact Number Call Girls Service In Goa 9316020077 Goa Call Girls Service
Contact Number Call Girls Service In Goa  9316020077 Goa  Call Girls ServiceContact Number Call Girls Service In Goa  9316020077 Goa  Call Girls Service
Contact Number Call Girls Service In Goa 9316020077 Goa Call Girls Servicesexy call girls service in goa
 
Call Girls Ramtek Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Ramtek Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Ramtek Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Ramtek Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
VIP Model Call Girls Wagholi ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Wagholi ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Wagholi ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Wagholi ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
BOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts Services
BOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts ServicesBOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts Services
BOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts Servicesdollysharma2066
 
Book Sex Workers Available Pune Call Girls Kondhwa 6297143586 Call Hot India...
Book Sex Workers Available Pune Call Girls Kondhwa  6297143586 Call Hot India...Book Sex Workers Available Pune Call Girls Kondhwa  6297143586 Call Hot India...
Book Sex Workers Available Pune Call Girls Kondhwa 6297143586 Call Hot India...Call Girls in Nagpur High Profile
 
Types of Pollution Powerpoint presentation
Types of Pollution Powerpoint presentationTypes of Pollution Powerpoint presentation
Types of Pollution Powerpoint presentationmarygraceaque1
 
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...
NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...
NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...Amil baba
 
Call Girls Talegaon Dabhade Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Talegaon Dabhade Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Talegaon Dabhade Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Talegaon Dabhade Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 

Recently uploaded (20)

VIP Model Call Girls Chakan ( Pune ) Call ON 8005736733 Starting From 5K to 2...
VIP Model Call Girls Chakan ( Pune ) Call ON 8005736733 Starting From 5K to 2...VIP Model Call Girls Chakan ( Pune ) Call ON 8005736733 Starting From 5K to 2...
VIP Model Call Girls Chakan ( Pune ) Call ON 8005736733 Starting From 5K to 2...
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 8005736733 Starting From 5K to...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 8005736733 Starting From 5K to...VIP Model Call Girls Hadapsar ( Pune ) Call ON 8005736733 Starting From 5K to...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 8005736733 Starting From 5K to...
 
Hot Call Girls 🫤 Malviya Nagar ➡️ 9711199171 ➡️ Delhi 🫦 Whatsapp Number
Hot Call Girls 🫤 Malviya Nagar ➡️ 9711199171 ➡️ Delhi 🫦 Whatsapp NumberHot Call Girls 🫤 Malviya Nagar ➡️ 9711199171 ➡️ Delhi 🫦 Whatsapp Number
Hot Call Girls 🫤 Malviya Nagar ➡️ 9711199171 ➡️ Delhi 🫦 Whatsapp Number
 
Kondhwa ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Kondhwa ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Kondhwa ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Kondhwa ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Get Premium Hoskote Call Girls (8005736733) 24x7 Rate 15999 with A/c Room Cas...
Get Premium Hoskote Call Girls (8005736733) 24x7 Rate 15999 with A/c Room Cas...Get Premium Hoskote Call Girls (8005736733) 24x7 Rate 15999 with A/c Room Cas...
Get Premium Hoskote Call Girls (8005736733) 24x7 Rate 15999 with A/c Room Cas...
 
Hot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Preet Vihar ☎ 9711199171 Book Your One night Stand
 
DENR EPR Law Compliance Updates April 2024
DENR EPR Law Compliance Updates April 2024DENR EPR Law Compliance Updates April 2024
DENR EPR Law Compliance Updates April 2024
 
Call Now ☎ Russian Call Girls Connaught Place @ 9899900591 # Russian Escorts ...
Call Now ☎ Russian Call Girls Connaught Place @ 9899900591 # Russian Escorts ...Call Now ☎ Russian Call Girls Connaught Place @ 9899900591 # Russian Escorts ...
Call Now ☎ Russian Call Girls Connaught Place @ 9899900591 # Russian Escorts ...
 
Call Girls Magarpatta Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Magarpatta Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Magarpatta Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Magarpatta Call Me 7737669865 Budget Friendly No Advance Booking
 
Contact Number Call Girls Service In Goa 9316020077 Goa Call Girls Service
Contact Number Call Girls Service In Goa  9316020077 Goa  Call Girls ServiceContact Number Call Girls Service In Goa  9316020077 Goa  Call Girls Service
Contact Number Call Girls Service In Goa 9316020077 Goa Call Girls Service
 
Call Girls Ramtek Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Ramtek Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Ramtek Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Ramtek Call Me 7737669865 Budget Friendly No Advance Booking
 
(NEHA) Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts 24x7
(NEHA) Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts 24x7(NEHA) Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts 24x7
(NEHA) Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts 24x7
 
VIP Model Call Girls Wagholi ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Wagholi ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Wagholi ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Wagholi ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
young Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort service
young Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort serviceyoung Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort service
young Whatsapp Call Girls in Delhi Cantt🔝 9953056974 🔝 escort service
 
BOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts Services
BOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts ServicesBOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts Services
BOOK Call Girls in (Dwarka) CALL | 8377087607 Delhi Escorts Services
 
Book Sex Workers Available Pune Call Girls Kondhwa 6297143586 Call Hot India...
Book Sex Workers Available Pune Call Girls Kondhwa  6297143586 Call Hot India...Book Sex Workers Available Pune Call Girls Kondhwa  6297143586 Call Hot India...
Book Sex Workers Available Pune Call Girls Kondhwa 6297143586 Call Hot India...
 
Types of Pollution Powerpoint presentation
Types of Pollution Powerpoint presentationTypes of Pollution Powerpoint presentation
Types of Pollution Powerpoint presentation
 
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(AISHA) Wagholi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...
NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...
NO1 Verified kala jadu karne wale ka contact number kala jadu karne wale baba...
 
Call Girls Talegaon Dabhade Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Talegaon Dabhade Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Talegaon Dabhade Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Talegaon Dabhade Call Me 7737669865 Budget Friendly No Advance Boo...
 

Chapter 09-Trees

  • 1. 9.1 INTRODUCTION A B, C D A 9.1.1 Basic Terminology Root node R R = NULL Sub-trees R NULL T1 , T2 , T3 R Leaf node Path path. A I A, D I Ancestor node A, C G K LeaRNINg OBjeCTIve So far, we have discussed linear data structures such as arrays, strings, stacks, and queues. In this chapter, we will learn about a non-linear data structure called tree. A tree is a structure which is mainly used to store data that is hierarchical in manipulate arithmetic expressions, construct symbol tables, and for syntax analysis. Trees chapTer 9
  • 2. 280 Data Structures Using C Descendant node A C, G, J K A Level number level number level number + 1 Degree In-degree Out-degree 9.2 TYPeS OF TReeS 9.2.1 general Trees 9.2.2 Forests B E F H I D A T1 Root node G KJ C T3 T2 Figure 9.1
  • 3. Trees 281 9.2.3 Binary Trees 'root' root = NULL R T1 T2 R T1 R T2 R Terminology Parent N T left successor S1 right successor S2 N parent S1 S2 S1 S2 N Level number level number parent's level number + 1 Degree of a node Sibling siblings Root node 2 4 5 6 7 12111098 3 1 T1 T2 Figure 9.3 Binary tree B F E A D H CB F G E D H C (a) (b) G Figure 9.2 Forest and its corresponding tree 2 4 5 6 7 12111098 3 1 Root node (Level 0) (Level 1) (Level 2) (Level 3) Figure 9.4 Levels in binary tree
  • 4. 282 Data Structures Using C Leaf node Similar binary trees T T¢ similar binary trees Copies T T¢ copies T¢ T Edge N n n – 1 Path . Depth depth N R N Height of a tree h h 2h – 1 h 2h – 1 n log2 (n+1) n. In-degree/out-degree of a node out-degree Complete Binary Trees A complete binary tree Tn n r T 2r 20 = 1 21 = 2 22 = 4 6 23 = 8 T13 K 2 × K 2 × K + 1 4 8 (2 × 4) 9 (2 × 4 + 1) K | K/2 | 4 | 4/2 | = 2 Tn Hn = | log2 (n + 1) | E A CB D Tree T Tree T¢ J F HG I Figure 9.5 Similar binary trees ED A CB Tree T Tree T¢ ED A CB Figure 9.6 ¢ is a copy 1 2 3 4 5 6 7 8 9 10 11 12 13 Figure 9.7 Complete binary tree
  • 5. Trees 283 T Extended Binary Trees T internal nodes external nodes Representation of Binary Trees in the Memory Linked representation of binary trees struct node { struct node *left; int data; struct node *right; }; ROOT ROOT = NULL X NULL 1 2 3 4 5 6 7 X 8 9 10 12X X X X X X XX X11 X X X Figure 9.9 Linked representation of a binary tree (a) (b) Figure 9.8 (a) Binary tree and (b) extended binary tree
  • 6. 284 Data Structures Using C 2 4 5 6 7 12111098 3 1 LEFT DATA RIGHT –1 –1 –1 5 9 20 1 –1 –1 –1 –1 –1 2 8 10 1 2 3 4 7 9 5 11 12 6 –1 –1 –1 18 12 14 8 –1 –1 16 ROOT 3 AVAIL 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 11 Figure 9.10 Binary tree T Figure 9.11 Linked representation of binary tree T example 9.1 Solution LEFT NAMES RIGHT 12 9 19 1 –1 –1 6 –1 –1 –1 11 –1 13 17 –1 –1 –1 20 –1 –1 –1 15 ROOT 3 AVAIL 7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Pallav Amar Deepak Janak Kuvam Rudraksh Raj Kunsh Tanush Ridhiman Sanjay Pallav Amar Deepak Janak KuvamRudraksh Raj KunshTanushRidhiman Sanjay
  • 7. Trees 285 Sequential representation of binary trees ∑ TREE ∑ is, TREE[1] ∑ K (2 × K) (2 × K+1) ∑ TREE (2h –1) h height ∑ NULL TREE[1] = NULL 9.2.4 Binary Search Trees A 9.2.5 expression Trees Exp = (a – b) + (c * d) example 9.2 Exp = ((a + b) – (c * d)) % ((e ^f) / (g – h)) Solution % + ^ – a b c d f g h i – Expression tree / example 9.3 Solution %/ + ^ – a b c d f g h i / 20 15 12 17 16 18 35 21 39 36 45 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 20 15 35 21 39 16 18 12 17 36 45 Figure 9.12 Binary tree and its sequential representation + a b c d Figure 9.13 Expression tree
  • 8. 286 Data Structures Using C [{(a/b) + (c*d)} ^ {(f % g)/(h – i)}] example 9.4 Exp = a + b / c * d – e Solution Exp = ((a + ((b/c) * d)) – e) 9.2.6 Tournament Trees n selection tree winner trees loser tree a, b, c, d, e, f, g h a b c d e f g h a, d, e a e a 9.3 CReaTINg a BINaRY TRee FROm a geNeRaL TRee Rule 1: Rule 2: Rule 3: example 9.5 + / a b c d – e Expression tree a b c d e f g h a a a d e e g Figure 9.14 B E F I J D A K G H C
  • 9. Trees 287 Step 1: A Step 2: A A A A A Step 3: B B is E C Step 4: C C is F D Step 5: D D is I D Step 6: I I I I J I Step 7: J J is K J DF B CE A DF B CE A I DF B CE A I J DF B CE A I J K K B CE A DF IG H J Step 8: E, F, G, H, K 9.4 TRaveRSINg a BINaRY TRee 9.4.1 Pre-order Traversal A A B B CE A B C A Figure 9.15 Binary tree
  • 10. 288 Data Structures Using C A, B, C depth-first traversal + – a b * c d (from Fig. 9.13) % – + a b * c d / ^ e f – g h (from Fig of Example 9.2) ^ + / a b * c d / % f g – h i (from Fig of Example 9.3) example 9.6 Solution TRAVERSAL ORDER: A, B, D, G, H, L, E, C, F, I, J, and K TRAVERSAL ORDER: A, B, D, C, D, E, F, G, H, and I 9.4.2 In-order Traversal B, A C symmetric traversal Step 1: Repeat Steps 2 to 4 while TREE != NULL Step 2: Write TREE DATA Step 3: PREORDER(TREE LEFT) Step 4: PREORDER(TREE RIGHT) [END OF LOOP] Step 5: END -> -> -> Figure 9.16 Algorithm for pre-order traversal Step 1: Repeat Steps 2 to 4 while TREE != NULL Step 2: INORDER(TREE LEFT) Step 3: Write TREE DATA Step 4: INORDER(TREE RIGHT) [END OF LOOP] Step 5: END -> -> -> Figure 9.17 Algorithm for in-order traversal A B C D E F G H I J KL G H I B C D E F A (a) (b)
  • 11. Trees 289 example 9.7 TRAVERSAL ORDER: G, D, H, L, B, E, A, C, I, F, K, and J TRAVERSAL ORDER: B, D, A, E, H, G, I, F, and C 9.4.3 Post-order Traversal B, C, A LRN example 9.8 TRAVERSAL ORDER: G, L, H, D, E, B, I, K, J, F, C, and A TRAVERSAL ORDER: D, B, H, I, G, F, E, C, and A 9.4.4 Level-order Traversal breadth-first traversal algorithm TRAVERSAL ORDER: A, B, C, D, E, F, G, H, I, J, L, and K (b)(a) TRAVERSAL ORDER: A, B, and C TRAVERSAL ORDER: A, B, C, D, E, F, G, H, and I (c) A CB HG B ED L JI C F K A B D G C F A E IH Figure 9.19 Binary trees Step 1: Repeat Steps 2 to 4 while TREE != NULL Step 2: POSTORDER(TREE LEFT) Step 3: POSTORDER(TREE RIGHT) Step 4: Write TREE DATA [END OF LOOP] Step 5: END -> -> -> Figure 9.18 Algorithm for post-order traversal
  • 12. 290 Data Structures Using C 9.4.5 Constructing a Binary Tree from Traversal Results In–order Traversal: D B E A F C G Pre–order Traversal: A B D E C F G Step 1 Step 2 Step 3 A DBHE FJCG A DBHE C IF G A DBHE C F G I A B D F G J HEI A B C D E H I J I I C Figure 9.21 Steps to show binary tree 9.5 HUFFmaN’S TRee '0' A DBE FCG D E A B FCG A B C D E F G Figure 9.20
  • 13. Trees 291 '1' n n – 1 external path length internal path length LI = 0 + 1 + 2 + 1 + 2 + 3 + 3 = 12 LE = 2 + 3 + 3 + 2 + 4 + 4 + 4 + 4 = 26 LI + 2 * n = 12 + 2 * 7 = 12 + 14 = 26 = LE LI + 2n = LE n n P P = W1 L1 + W2 L2 + …. + Wn Ln Wi Li Ni example 9.9 T1 , T2 T3 5 2 2 3 11 5 2 3 4 5 7 5 2 3 11 T1 T2 T3 Binary tree Solution T1 P1 = 2◊3 + 3◊3 + 5◊2 + 11◊3 + 5◊3 + 2◊2 = 6 + 9 + 10 + 33 + 15 + 4 = 77 T2 P2 = 5◊2 + 7◊2 + 3◊3 + 4◊3 + 2◊2 = 10 + 14 + 9 + 12 + 4 = 49 T3 P3 = 2◊3 + 3◊3 + 5◊2 + 11◊1 = 6 + 9 + 10 + 11 = 36 Technique n Figure 9.22 Binary tree
  • 14. 292 Data Structures Using C Step 1: Create a leaf node for each character. Add the character and its weight or frequency of occurrence to the priority queue. Step 2: Repeat Steps 3 to 5 while the total number of nodes in the queue is greater than 1. Step 3: Remove two nodes that have the lowest weight (or highest priority). Step 4: Create a new internal node by merging these two nodes as children and with weight equal to the sum of the two nodes' weights. Step 5: Add the newly created node to the queue. Figure 9.23 Huffman algorithm example 9.10 A 7 B 9 C 11 D 14 E 18 F 21 G 27 H 29 I 35 J 40 C 11 D 14 E 18 F 21 G 27 H 29 I 35 J 40 16 A 7 B 9 25 A 7 B 9 16 A 7 B 9 C 11 D 14 E 18 F 21 G 27 H 29 I 35 J 40 25 F 21 G 27 H 29 I 35 J 40 E 18 C 11 D 14 16 34 C 11 D 14 25 46 F 21 G 27 H 29 I 35 J 40 E 18 16 34 A 7 B 9
  • 15. Trees 293 86 25 46 J 40 C D F 21 56 G 27 H 29 I 35 69 E16 34 125 211 11 1418 A 7 B 9 5646 I 35 J 40 34 J 40 46 56 69 A 7 B 9 8656 69 86 25 46 J 40 C 11 D 14 F 21 56 G 27 H 29 I 35 69 E 18 A 7 B 9 16 34 125 25 46 J 40 G 27 H 29 C 11 D 14 F 21 I 35 E 18 A 7 B 9 16 34 25 G 27 H 29 C 11 D 14 I 35 E 18 16 34F 21 C 11 D 14 25 F 21 G 27 H 29 E 18 16 A 7 B 9
  • 16. 294 Data Structures Using C Data Coding r 2r r=1 A B B r=2 r=3 ABBBBBBAAAACDEFGGGGH 000001001001001001001000000000000010011100101110110110110111 a, e, i r w, x, y, z A, E, R, W, X, Y, Z A E R X Y W Z 0 1 0 1 0 0 0 0 1 1 1 1 Figure 9.24 Huffman tree 9.6 aPPLICaTIONS OF TReeS ∑ Table 9.3 Characters with their codes Character Code A 00 E 01 R 11 W 1010 X 1000 Y 1001 Z 1011 Table 9.1 Range of characters that can be coded using r = 2 Code Character 00 A 01 B 10 C 11 D Table 9.2 Range of characters that can be coded using r = 3 Code Character 000 A 001 B 010 C 011 D 100 E 101 F 110 G 111 H