6 1 3 10 10 10 2 1 0 6 x 100+ 1 x 10 + 3 x 1 =613 Base 10 digits {0...9} Base 10 digits {0...9}
-
Upload
thomas-riley -
Category
Documents
-
view
222 -
download
0
Transcript of 6 1 3 10 10 10 2 1 0 6 x 100+ 1 x 10 + 3 x 1 =613 Base 10 digits {0...9} Base 10 digits {0...9}
6 1 3
10 10 102 1 0
6 x 100+ 1 x 10 + 3 x 1
=613
Base 10
digits {0...9}
Base 10
digits {0...9}
1 1 0 1
2 22 1 22 03
1 x 8+ 1 x 4+ 0 x 2+ 1 x 1
= 13
Base 2
digits {0, 1}
Base 2
digits {0, 1}
decimal binary1 12 103 114 1005 1016 1107 1118 10009 100110 101011 101112 110013 110114 111015 1111
The binary equivalents of some decimal numbers.
The binary equivalents of some decimal numbers.
parent
Left child right child
A binary tree consists of a set of nodes each of which can have at most two children.
A binary tree consists of a set of nodes each of which can have at most two children.
root
leaf
leafleaf
The top node of the tree is called the root. A leaf is a node with no descendants.
The top node of the tree is called the root. A leaf is a node with no descendants.
1 1 0 1
2 22 1 22 03
The binary digits (bits) in the computer’s memory are initially set to zero. To represent a number, the appropriate bits are set to 1.
The binary digits (bits) in the computer’s memory are initially set to zero. To represent a number, the appropriate bits are set to 1.
0 0 0 0
13 (dec)
4 (dec) = Multiplying by 2 in machine language is accomplished by shifting left one bit.
Multiplying by 2 in machine language is accomplished by shifting left one bit.
000100
4 (dec) =
8 (dec) =
Multiplying by 2 in machine language is accomplished by shifting left one bit.
Multiplying by 2 in machine language is accomplished by shifting left one bit.
000100
001000
4 (dec) =
8 (dec) =
16 (dec) =
Multiplying by 2 in machine language is accomplished by shifting left one bit.
Multiplying by 2 in machine language is accomplished by shifting left one bit.
000100
001000
010000
4 (dec) =
8 (dec) =
16 (dec) =
000100
001000
010000
5 (dec) =
9 (dec) =
17 (dec) =
000101
001001
010001
We obtain the next integer by adding a 1 to the binary number.
We obtain the next integer by adding a 1 to the binary number.
n
2n 2n+1
Construct a tree using the following: If the parent ‘s node number is n, the left child’s is 2*n and the right child‘s is 2*n + 1.
Construct a tree using the following: If the parent ‘s node number is n, the left child’s is 2*n and the right child‘s is 2*n + 1.
1
We assign 1 to the root’s node numberWe assign 1 to the root’s node number
1
2
Then, the left child’s node number is 2Then, the left child’s node number is 2
1
2 3
And the right child’s node number is 3.And the right child’s node number is 3.
1
2 3
4 5 6 7
0
A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge.
A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge.
1
2 3
4 5 6 7
0
0
A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge.
A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge.
1
2 3
4 5 6 7
0
0 0
A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge.
A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge.
1
2 3
4 5 6 7
0
0
1
0
A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge and a 1 on each right edge of a binary tree.
A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge and a 1 on each right edge of a binary tree.
1
2 3
4 5 6 7
0
0 1
1
0
A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge and a 1 on each right edge of a binary tree.
A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge and a 1 on each right edge of a binary tree.
1
2 3
4 5 6 7
0
0 1
1
10
A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge and a 1 on each right edge of a binary tree.
A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge and a 1 on each right edge of a binary tree.
1
2 3
4 5 6 7
0
0
To convert 5 to binary, start by writing the lower-most 1 on the path from node 5 to the root.
To convert 5 to binary, start by writing the lower-most 1 on the path from node 5 to the root.
1
1
1
2 3
4 5 6 7
0
0
To the left of the 1, write the digit for the next edge on the upward path to the root, namely, 0.
To the left of the 1, write the digit for the next edge on the upward path to the root, namely, 0.
1
01
1
2 3
4 5 6 7
0
0
Finally, to the left of the 0, place a 1. This represents the node number of the root, 1, which is the same in binary and decimal.
Finally, to the left of the 0, place a 1. This represents the node number of the root, 1, which is the same in binary and decimal.
1
101
1
2 3
4 5 6 7
0
0 1
1
10
100 101 110 111
The node numbers at the leaves converted to binary numbers.
The node numbers at the leaves converted to binary numbers.
1
2 3
4 5 6 7
0
0 1
1
10
100 101 110 111
10 111
Placing a 0 on each left edge is equivalent to shifting left, ie., multiplying by 2. Placing a 1 on the right edge means you are adding 1 to the left child’s value.
Placing a 0 on each left edge is equivalent to shifting left, ie., multiplying by 2. Placing a 1 on the right edge means you are adding 1 to the left child’s value.
67
33 1
Express 67 in decimalExpress 67 in decimal
1 (bin)
67
33
16
1
1
11 (bin)
67
33
16
8
1
1
0
011 (bin)
67
33
16
8
4
1
1
0
0
0011 (bin)
67
33
16
8
4
2
1
1
0
0
0
00011 (bin)
67
33
16
8
4
2
1
1
1
0
0
0
0
000011 (bin)
67
33
16
8
4
2
1
1
1
0
0
0
0
67 (dec) = 1000011 (bin)
Place 1 at the left since the root node contains 1.
Place 1 at the left since the root node contains 1.
The ascii code in decimal and binary for some characters. Thus it requires 7 bits to represent each character.
The ascii code in decimal and binary for some characters. Thus it requires 7 bits to represent each character.
character ascii code binarya 97 1100001
b 98 1100010
c 99 1100011
d 100 1100100
e 101 1100101
f 102 1100110
g 103 1100111
h 104 1101000
i 105 1101001
j 106 1101010
k 107 1101011
l 108 1101100
m 109 1101101
n 110 1101110
American Standard Code for Information InterchangeAmerican Standard Code for Information Interchange
a c
b
Symbol a: 00
0
1
Symbol b: 00
Symbol c : 1
The code 001 can be decoded as aac or bc. Thus the code is ambiguous.
The code 001 can be decoded as aac or bc. Thus the code is ambiguous.
aSymbol a: 00
Symbol b: 01The code 01 is decoded as b. Before, however, you reach the end of the string 01, you would think that 0 corresponds to a. The code requires you to scan ahead. This is called non-instantaneous code and is inefficient as coding scheme.
The code 01 is decoded as b. Before, however, you reach the end of the string 01, you would think that 0 corresponds to a. The code requires you to scan ahead. This is called non-instantaneous code and is inefficient as coding scheme.
b
1
a b
c
0
0
1
1
Symbol a: 00
Symbol b: 01
Symbol c: 1
If the characters are only in the leaves, the code is unique and instantaneous. Such a code exhibits the prefix property.
If the characters are only in the leaves, the code is unique and instantaneous. Such a code exhibits the prefix property.
a b
c
0
0
1
1
Symbol a: 00
Symbol b: 01
Symbol c: 1
Let’s decode 10001Let’s decode 10001
a b
c
0
0
1
1
Symbol a: 00
Symbol b: 01
Symbol c: 1
1000110001
a b
c
0
0
1
1
Symbol a: 00
Symbol b: 01
Symbol c: 1
1000110001
cc
a b
c
0
0
1
1
Symbol a: 00
Symbol b: 01
Symbol c: 1
1000110001
cc
a b
c
0
0
1
1
Symbol a: 00
Symbol b: 01
Symbol c: 1
1000110001
cc
a b
c
0
0
1
1
Symbol a: 00
Symbol b: 01
Symbol c: 1
1000110001
caca
a b
c
0
0
1
1
Symbol a: 00
Symbol b: 01
Symbol c: 1
1000110001
caca
a b
c
0
0
1
1
Symbol a: 00
Symbol b: 01
Symbol c: 1
1000110001
caca
a b
c
0
0
1
1
Symbol a: 00
Symbol b: 01
Symbol c: 1
1000110001
cabcab
Letter Frequencya 11b 2g 9h 4
Letters occurring in a paragraph and their frequency of occurrence. How can we encode these letters so that the resultant code is minimal?
Letters occurring in a paragraph and their frequency of occurrence. How can we encode these letters so that the resultant code is minimal?
b, 2 h, 4 g, 9 a, 11
A list of nodes containing the letters and frequencies. The list is sorted by frequency.
A list of nodes containing the letters and frequencies. The list is sorted by frequency.
b, 2 h, 4
g, 9 a, 11
Remove the first two nodes, add their frequencies, and create a parent node with that frequency. Letters will appear in only the leaves of the final tree.
Remove the first two nodes, add their frequencies, and create a parent node with that frequency. Letters will appear in only the leaves of the final tree.
*, 6
b, 2 h, 4
g, 9 a, 11
Insert the parent node with its children in its sorted position in the list. This type of list and its operations is called a priority queue.
Insert the parent node with its children in its sorted position in the list. This type of list and its operations is called a priority queue.
*, 6
b, 2 h, 4
g, 9
a, 11
*, 6
*, 15
Remove the first two nodes again, add their frequencies, and create a parent node with that frequency.
Remove the first two nodes again, add their frequencies, and create a parent node with that frequency.
b, 2 h, 4
g, 9
a, 11
*, 6
*, 15
Insert the parent node with its children in its sorted position in the list.
Insert the parent node with its children in its sorted position in the list.
b, 2 h, 4
g, 9
a, 11
*, 6
*, 15
By continuing the process, we get the final tree. The leaves are the only nodes containing letters.
By continuing the process, we get the final tree. The leaves are the only nodes containing letters.
*, 26
b h
g
a
This tree is called a Huffman tree. Here it is shown with only the leaves labeled.
This tree is called a Huffman tree. Here it is shown with only the leaves labeled.
b h
g
a
Label the edges with 0’s and 1’s as we did for the binary numbers.
Label the edges with 0’s and 1’s as we did for the binary numbers.
0
00
1
1
1
b h
g
a
The letters with their Huffman codes. The letters with the higher frequencies have smaller Huffman codes.
The letters with their Huffman codes. The letters with the higher frequencies have smaller Huffman codes.
0
00
1
1
1
letter frequency Huffman codea 11 0g 9 11h 4 101b 2 100
b h
g
a
Let’s decode 100011Let’s decode 100011
0
00
1
1
1
b h
g
a
100011 100011
0
00
1
1
1
b h
g
a
100011 100011
0
00
1
1
1
b h
g
a
100011 100011
0
00
1
1
1
b h
g
a
100011 We hit a leaf, print letter, 100011 We hit a leaf, print letter,
0
00
1
1
1
Resultant code: bResultant code: b
b h
g
a
100011 We hit a leaf, print letter & return to root. 100011 We hit a leaf, print letter & return to root.
0
00
1
1
1
Resultant code: bResultant code: b
b h
g
a
100011 We hit a leaf, print letter 100011 We hit a leaf, print letter
0
00
1
1
1
Resultant code: baResultant code: ba
b h
g
a
100011 We hit a leaf, print letter & return to root. 100011 We hit a leaf, print letter & return to root.
0
00
1
1
1
Resultant code: baResultant code: ba
b h
g
a
100011 100011
0
00
1
1
1
Resultant code: baResultant code: ba
b h
g
a
100011 We hit a leaf and print letter. 100011 We hit a leaf and print letter.
0
00
1
1
1
Resultant code: bagResultant code: bag
bag : 100011 in Huffman code
bag : 1100010
bag : 100011 in Huffman code
bag : 1100010
character ascii code binarya 97 1100001
b 98 1100010
c 99 1100011
d 100 1100100
e 101 1100101
f 102 1100110
g 103 1100111
h 104 1101000
i 105 1101001
j 106 1101010
k 107 1101011
l 108 1101100
m 109 1101101
n 110 1101110
bag : 100011 in Huffman code
bag : 11000101100001
bag : 100011 in Huffman code
bag : 11000101100001
character ascii code binarya 97 1100001
b 98 1100010
c 99 1100011
d 100 1100100
e 101 1100101
f 102 1100110
g 103 1100111
h 104 1101000
i 105 1101001
j 106 1101010
k 107 1101011
l 108 1101100
m 109 1101101
n 110 1101110
bag : 100011 in Huffman code
bag : 110001011000011100111 in ascii code
bag : 100011 in Huffman code
bag : 110001011000011100111 in ascii code
character ascii code binarya 97 1100001
b 98 1100010
c 99 1100011
d 100 1100100
e 101 1100101
f 102 1100110
g 103 1100111
h 104 1101000
i 105 1101001
j 106 1101010
k 107 1101011
l 108 1101100
m 109 1101101
n 110 1101110
12,b 13,h
7,g
2,a
If you number the nodes as we did when we converted decimal to binary, you can get the Huffman code from the node numbers.
If you number the nodes as we did when we converted decimal to binary, you can get the Huffman code from the node numbers.
12,b 13,h
7,g
2,a
Letter Node Binary Huffman Codea 2 10 0g 7 111 11h 13 1101 101b 12 1100 100
The Huffman code is obtained from the binary by removing the leading 1.
The Huffman code is obtained from the binary by removing the leading 1.
"Baseball's Sad Lexicon"
These are the saddest of possible words: "Tinker to Evers to Chance." Trio of bear cubs, and fleeter than birds, Tinker and Evers and Chance. Ruthlessly pricking our gonfalon bubble, Making a Giant hit into a double-- Words that are heavy with nothing but trouble: "Tinker to Evers to Chance." Franklin Pierce Adams
http://memory.loc.gov/ammem/bbhtml/bb1.html