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

<ul><li> Slide 1 </li> <li> 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} </li> <li> Slide 2 </li> <li> 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} </li> <li> Slide 3 </li> <li> The binary equivalents of some decimal numbers. </li> <li> Slide 4 </li> <li> parent Left child right child A binary tree consists of a set of nodes each of which can have at most two children. </li> <li> Slide 5 </li> <li> root leaf The top node of the tree is called the root. A leaf is a node with no descendants. </li> <li> Slide 6 </li> <li> 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) </li> <li> Slide 7 </li> <li> 4 (dec) = Multiplying by 2 in machine language is accomplished by shifting left one bit. 000100 </li> <li> Slide 8 </li> <li> 4 (dec) = 8 (dec) = Multiplying by 2 in machine language is accomplished by shifting left one bit. 000100 001000 </li> <li> Slide 9 </li> <li> 4 (dec) = 8 (dec) = 16 (dec) = Multiplying by 2 in machine language is accomplished by shifting left one bit. 000100 001000 010000 </li> <li> Slide 10 </li> <li> 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. </li> <li> Slide 11 </li> <li> 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. </li> <li> Slide 12 </li> <li> 1 We assign 1 to the roots node number </li> <li> Slide 13 </li> <li> 1 2 Then, the left childs node number is 2 </li> <li> Slide 14 </li> <li> 1 2 3 And the right childs node number is 3. </li> <li> Slide 15 </li> <li> 1 23 4567 0 A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge. </li> <li> Slide 16 </li> <li> 1 23 4567 0 0 </li> <li> Slide 17 </li> <li> 1 23 4567 0 0 0 </li> <li> Slide 18 </li> <li> 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. </li> <li> Slide 19 </li> <li> 1 23 4567 0 0 1 1 0 </li> <li> Slide 20 </li> <li> 1 23 4567 0 0 1 1 10 </li> <li> Slide 21 </li> <li> 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 </li> <li> Slide 22 </li> <li> 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 </li> <li> Slide 23 </li> <li> 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 </li> <li> Slide 24 </li> <li> 1 23 4567 0 0 1 1 10 100101110111 The node numbers at the leaves converted to binary numbers. </li> <li> Slide 25 </li> <li> 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. </li> <li> Slide 26 </li> <li> 67 33 1 Express 67 in decimal 1 (bin) </li> <li> Slide 27 </li> <li> 67 33 16 1 1 11 (bin) </li> <li> Slide 28 </li> <li> 67 33 16 8 1 1 0 011 (bin) </li> <li> Slide 29 </li> <li> 67 33 16 8 4 1 1 0 0 0011 (bin) </li> <li> Slide 30 </li> <li> 67 33 16 8 4 2 1 1 0 0 0 00011 (bin) </li> <li> Slide 31 </li> <li> 67 33 16 8 4 2 1 1 1 0 0 0 0 000011 (bin) </li> <li> Slide 32 </li> <li> 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. </li> <li> Slide 33 </li> <li> 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 </li> <li> Slide 34 </li> <li> 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. </li> <li> Slide 35 </li> <li> 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 </li> <li> Slide 36 </li> <li> 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. </li> <li> Slide 37 </li> <li> a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 Lets decode 10001 </li> <li> Slide 38 </li> <li> a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 </li> <li> Slide 39 </li> <li> a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 c c </li> <li> Slide 40 </li> <li> a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 c c </li> <li> Slide 41 </li> <li> a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 c c </li> <li> Slide 42 </li> <li> a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 ca </li> <li> Slide 43 </li> <li> a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 ca </li> <li> Slide 44 </li> <li> a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 ca </li> <li> Slide 45 </li> <li> a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 cab </li> <li> Slide 46 </li> <li> Letters occurring in a paragraph and their frequency of occurrence. How can we encode these letters so that the resultant code is minimal? </li> <li> Slide 47 </li> <li> b, 2h, 4g, 9a, 11 A list of nodes containing the letters and frequencies. The list is sorted by frequency. </li> <li> Slide 48 </li> <li> 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 </li> <li> Slide 49 </li> <li> 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 </li> <li> Slide 50 </li> <li> 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. </li> <li> Slide 51 </li> <li> b, 2h, 4 g, 9 a, 11 *, 6 *, 15 Insert the parent node with its children in its sorted position in the list. </li> <li> Slide 52 </li> <li> 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 </li> <li> Slide 53 </li> <li> bh g a This tree is called a Huffman tree. Here it is shown with only the leaves labeled. </li> <li> Slide 54 </li> <li> bh g a Label the edges with 0s and 1s as we did for the binary numbers. 0 0 0 1 1 1 </li> <li> Slide 55 </li> <li> 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 </li> <li> Slide 56 </li> <li> bh g a Lets decode 100011 0 0 0 1 1 1 </li> <li> Slide 57 </li> <li> bh g a 100011 0 0 0 1 1 1 </li> <li> Slide 58 </li> <li> bh g a 0 0 0 1 1 1 </li> <li> Slide 59 </li> <li> bh g a 0 0 0 1 1 1 </li> <li> Slide 60 </li> <li> bh g a 100011 We hit a leaf, print letter, 0 0 0 1 1 1 Resultant code: b </li> <li> Slide 61 </li> <li> bh g a 100011 We hit a leaf, print letter &amp; return to root. 0 0 0 1 1 1 Resultant code: b </li> <li> Slide 62 </li> <li> bh g a 100011 We hit a leaf, print letter 0 0 0 1 1 1 Resultant code: ba </li> <li> Slide 63 </li> <li> bh g a 100011 We hit a leaf, print letter &amp; return to root. 0 0 0 1 1 1 Resultant code: ba </li> <li> Slide 64 </li> <li> bh g a 100011 0 0 0 1 1 1 Resultant code: ba </li> <li> Slide 65 </li> <li> bh g a 100011 We hit a leaf and print letter. 0 0 0 1 1 1 Resultant code: bag </li> <li> Slide 66 </li> <li> bag : 100011 in Huffman code bag : 1100010 bag : 100011 in Huffman code bag : 1100010 </li> <li> Slide 67 </li> <li> bag : 100011 in Huffman code bag : 11000101100001 bag : 100011 in Huffman code bag : 11000101100001 </li> <li> Slide 68 </li> <li> bag : 100011 in Huffman code bag : 110001011000011100111 in ascii code bag : 100011 in Huffman code bag : 110001011000011100111 in ascii code </li> <li> Slide 69 </li> <li> 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. </li> <li> Slide 70 </li> <li> 12,b13,h 7,g 2,a The Huffman code is obtained from the binary by removing the leading 1. </li> <li> Slide 71 </li> <li> "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 </li> </ul>