Discrete Mathematics
Discrete Mathematics
Trees
1
Outline of Today’s Lecture
2
Universal Address System
3
Universal Address System of
an Ordered Rooted Tree
4
Address This Tree
5
Solution
6
Think Carefully
7
Eccentricity
8
Center = c
Finding Eccentricity
Ecc(a) = 4
Ecc(b) = 5
Ecc(c) = 3
Ecc(d) = 4
Ecc(e) = 4
Ecc(f) = 5
Ecc(g) = 5
Ecc(h) = 5
Ecc(i) = 5
Ecc(j) = 6
Ecc(k) = 6
Ecc(l) = 6 9
Problem 1
Consider the problem of using bit strings to encode the
letters of the English alphabet (where no distinction is
made between lowercase and uppercase letters).
We can represent each letter with a bit string of length 5.
The total number of bits used to encode data is five
times the number of characters in the text when each
character is encoded with five bits.
Is it possible to find a coding scheme of these letters
such that, when data are coded, fewer bits are used? We
can save memory and reduce transmission time if this
can be done.
10
Problem 2
e=0
a = 10
t = 110
n = 1110
s = 1111
13
Decode 11111011100
1111 = s
Now string becomes = 1011100
10 = a
Now string becomes = 11100
1110 = n
0 =e
14
Construct the BT for Prefix
Codes
0 1
0 1 0 1
A D E
0 1
B C
15
Huffman Coding
A 0 A
0 1
B 100
0 D
C 101 1
D 11 B C
16
Construction of Huffman Trees
P(A)= 0.4, P(B)= 0.1, P(C)= 0.3, P(D)= 0.1, P(E)= 0.1
D E
17
Construction of Huffman Trees
0.1 0.2 0.3 0.4
B C A
0 1
D E
B
0 1
D E
18
Construction of Huffman Trees
B C
0 1 0 1
D E B
0 1
D E
19
Construction of Huffman Trees
1.0
0.4 0.6
A
0 1
0 1
C A
0 1
0 1
B C
0 1 0 1
D E B
0 1
D E
20
Construction of Huffman Trees
0 1
A=0
A B = 100
0 1
C = 11
C D = 1010
0 1
E = 1011
B
0 1
D E
21
Another Example
22
Building a Tree
Scan the original text
23
Building a Tree
Scan the original text
E e r i space ysnarlk.
24
Building a Tree
Scan the original text
Eerie eyes seen near lake.
What is the frequency of each character in the text?
25
Building a Tree
Prioritize characters
26
Building a Tree
After inserting all nodes
E i y l k . r s n a sp e
1 1 1 1 1 1 2 2 2 2 4 8
27
Building a Tree
y l k . r s n a sp e
1 1 1 1 2 2 2 2 4 8
E i
28
Building a Tree
y l k . r s n a sp e
1 1 1 1 2 2 2 2 4 8
E i
29
Building a Tree
k . r s n a sp e
1 1 2 2 2 2 4 8
E i
y l
30
Building a Tree
2
k . r s n a 2 sp e
1 1 2 2 2 2 4 8
y l
E i
31
Building a Tree
r s n a 2 2 sp e
2 2 2 2 4 8
y l
E i
k .
32
Building a Tree
r s n a 2 2 sp e
2
2 2 2 2 4 8
E i y l k .
33
Building a Tree
n a 2 sp e
2 2
2 2 4 8
E i y l k .
r s
34
Building a Tree
n a 2 sp e
2 4
2
2 2 4 8
E i y l k . r s
35
Building a Tree
2 4 e
2 2 sp
8
4
y l k . r s
E i
n a
36
Building a Tree
2 4 4 e
2 2 sp
8
4
y l k . r s n a
E i
37
Building a Tree
4 4 e
2 sp
8
4
k . r s n a
2 2
E i y l
38
Building a Tree
4 4 4
2 sp e
4 2 2 8
k . r s n a
E i y l
39
Building a Tree
4 4 4
e
2 2 8
r s n a
E i y l
2 sp
k .
40
Building a Tree
4 4 4 6 e
2 sp 8
r s n a 2 2
k .
E i y l
41
Building a Tree
4 6 e
2 2 2 8
sp
E i y l k .
8
4 4
r s n a
42
Building a Tree
4 6 e 8
2 2 2 8
sp
4 4
E i y l k .
r s n a
43
Building a Tree
8
e
8
4 4
10
r s n a
4
6
2 2
2 sp
E i y l k .
44
Building a Tree
8 10
e
8 4
4 4
6
2 2 2
r s n a sp
E i y l k .
45
Building a Tree
10
16
4
6
2 2 e 8
2 sp
E i y l k . 4 4
r s n a
46
Building a Tree
10 16
4
6
e 8
2 2
2 sp
4 4
E i y l k .
r s n a
47
Building a Tree
26
16
10
4 e 8
6
2 2 2 sp 4 4
E i y l k .
r s n a
51