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}

Download 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}

Post on 23-Dec-2015

217 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • Slide 1
  • 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}
  • Slide 2
  • 1 1 0 1 22 21 2 2 03 1 x 8+ 1 x 4+ 0 x 2+ 1 x 1 = 13 Base 2 digits {0, 1} Base 2 digits {0, 1}
  • Slide 3
  • The binary equivalents of some decimal numbers.
  • Slide 4
  • parent Left child right child A binary tree consists of a set of nodes each of which can have at most two children.
  • Slide 5
  • root leaf The top node of the tree is called the root. A leaf is a node with no descendants.
  • Slide 6
  • 1 1 0 1 22 21 2 2 03 The binary digits (bits) in the computers memory are initially set to zero. To represent a number, the appropriate bits are set to 1. 0000 13 (dec)
  • Slide 7
  • 4 (dec) = Multiplying by 2 in machine language is accomplished by shifting left one bit. 000100
  • Slide 8
  • 4 (dec) = 8 (dec) = Multiplying by 2 in machine language is accomplished by shifting left one bit. 000100 001000
  • Slide 9
  • 4 (dec) = 8 (dec) = 16 (dec) = Multiplying by 2 in machine language is accomplished by shifting left one bit. 000100 001000 010000
  • Slide 10
  • 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.
  • Slide 11
  • n 2n2n+1 Construct a tree using the following: If the parent s node number is n, the left childs is 2*n and the right childs is 2*n + 1.
  • Slide 12
  • 1 We assign 1 to the roots node number
  • Slide 13
  • 1 2 Then, the left childs node number is 2
  • Slide 14
  • 1 2 3 And the right childs node number is 3.
  • Slide 15
  • 1 23 4567 0 A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge.
  • Slide 16
  • 1 23 4567 0 0
  • Slide 17
  • 1 23 4567 0 0 0
  • Slide 18
  • 1 23 4567 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.
  • Slide 19
  • 1 23 4567 0 0 1 1 0
  • Slide 20
  • 1 23 4567 0 0 1 1 10
  • Slide 21
  • 1 23 4567 0 0 To convert 5 to binary, start by writing the lower-most 1 on the path from node 5 to the root. 1 1
  • Slide 22
  • 1 23 4567 0 0 To the left of the 1, write the digit for the next edge on the upward path to the root, namely, 0. 1 0101
  • Slide 23
  • 1 23 4567 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. 1 101
  • Slide 24
  • 1 23 4567 0 0 1 1 10 100101110111 The node numbers at the leaves converted to binary numbers.
  • Slide 25
  • 1 23 4567 0 0 1 1 10 100101110111 1011 1 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 childs value.
  • Slide 26
  • 67 33 1 Express 67 in decimal 1 (bin)
  • Slide 27
  • 67 33 16 1 1 11 (bin)
  • Slide 28
  • 67 33 16 8 1 1 0 011 (bin)
  • Slide 29
  • 67 33 16 8 4 1 1 0 0 0011 (bin)
  • Slide 30
  • 67 33 16 8 4 2 1 1 0 0 0 00011 (bin)
  • Slide 31
  • 67 33 16 8 4 2 1 1 1 0 0 0 0 000011 (bin)
  • Slide 32
  • 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.
  • Slide 33
  • The ascii code in decimal and binary for some characters. Thus it requires 7 bits to represent each character. American Standard Code for Information Interchange
  • Slide 34
  • a c b Symbol a: 0 0 0 1 Symbol b: 00 Symbol c : 1 The code 001 can be decoded as aac or bc. Thus the code is ambiguous.
  • Slide 35
  • a Symbol a: 0 0 Symbol b: 01 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
  • Slide 36
  • 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.
  • Slide 37
  • a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 Lets decode 10001
  • Slide 38
  • a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001
  • Slide 39
  • a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 c c
  • Slide 40
  • a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 c c
  • Slide 41
  • a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 c c
  • Slide 42
  • a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 ca
  • Slide 43
  • a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 ca
  • Slide 44
  • a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 ca
  • Slide 45
  • a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 cab
  • Slide 46
  • Letters occurring in a paragraph and their frequency of occurrence. How can we encode these letters so that the resultant code is minimal?
  • Slide 47
  • b, 2h, 4g, 9a, 11 A list of nodes containing the letters and frequencies. The list is sorted by frequency.
  • Slide 48
  • b, 2h, 4 g, 9a, 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. *, 6
  • Slide 49
  • b, 2h, 4 g, 9a, 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. *, 6
  • Slide 50
  • b, 2h, 4 g, 9 a, 11 *, 6 *, 15 Remove the first two nodes again, add their frequencies, and create a parent node with that frequency.
  • Slide 51
  • b, 2h, 4 g, 9 a, 11 *, 6 *, 15 Insert the parent node with its children in its sorted position in the list.
  • Slide 52
  • b, 2h, 4 g, 9 a, 11 *, 6 *, 15 By continuing the process, we get the final tree. The leaves are the only nodes containing letters. *, 26
  • Slide 53
  • bh g a This tree is called a Huffman tree. Here it is shown with only the leaves labeled.
  • Slide 54
  • bh g a Label the edges with 0s and 1s as we did for the binary numbers. 0 0 0 1 1 1
  • Slide 55
  • bh g a The letters with their Huffman codes. The letters with the higher frequencies have smaller Huffman codes. 0 0 0 1 1 1
  • Slide 56
  • bh g a Lets decode 100011 0 0 0 1 1 1
  • Slide 57
  • bh g a 100011 0 0 0 1 1 1
  • Slide 58
  • bh g a 0 0 0 1 1 1
  • Slide 59
  • bh g a 0 0 0 1 1 1
  • Slide 60
  • bh g a 100011 We hit a leaf, print letter, 0 0 0 1 1 1 Resultant code: b
  • Slide 61
  • bh g a 100011 We hit a leaf, print letter & return to root. 0 0 0 1 1 1 Resultant code: b
  • Slide 62
  • bh g a 100011 We hit a leaf, print letter 0 0 0 1 1 1 Resultant code: ba
  • Slide 63
  • bh g a 100011 We hit a leaf, print letter & return to root. 0 0 0 1 1 1 Resultant code: ba
  • Slide 64
  • bh g a 100011 0 0 0 1 1 1 Resultant code: ba
  • Slide 65
  • bh g a 100011 We hit a leaf and print letter. 0 0 0 1 1 1 Resultant code: bag
  • Slide 66
  • bag : 100011 in Huffman code bag : 1100010 bag : 100011 in Huffman code bag : 1100010
  • Slide 67
  • bag : 100011 in Huffman code bag : 11000101100001 bag : 100011 in Huffman code bag : 11000101100001
  • Slide 68
  • bag : 100011 in Huffman code bag : 110001011000011100111 in ascii code bag : 100011 in Huffman code bag : 110001011000011100111 in ascii code
  • Slide 69
  • 12,b13,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.
  • Slide 70
  • 12,b13,h 7,g 2,a The Huffman code is obtained from the binary by removing the leading 1.
  • Slide 71
  • "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

Recommended

View more >