Presentation is loading. Please wait.

Presentation is loading. Please wait.

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}

Similar presentations


Presentation on theme: "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}"— Presentation transcript:

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}

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}

3 The binary equivalents of some decimal numbers.

4 parent Left child right child A binary tree consists of a set of nodes each of which can have at most two children.

5 root leaf The top node of the tree is called the root. A leaf is a node with no descendants.

6 1 1 0 1 22 21 2 2 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. 0000 13 (dec)

7 4 (dec) = Multiplying by 2 in machine language is accomplished by shifting left one bit. 000100

8 4 (dec) = 8 (dec) = Multiplying by 2 in machine language is accomplished by shifting left one bit. 000100 001000

9 4 (dec) = 8 (dec) = 16 (dec) = Multiplying by 2 in machine language is accomplished by shifting left one bit. 000100 001000 010000

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.

11 n 2n2n+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.

12 1 We assign 1 to the root’s node number

13 1 2 Then, the left child’s node number is 2

14 1 2 3 And the right child’s node number is 3.

15 1 23 4567 0 A graphical way of getting the binary equivalents of decimal numbers. Place a 0 on each left edge.

16 1 23 4567 0 0

17 1 23 4567 0 0 0

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.

19 1 23 4567 0 0 1 1 0

20 1 23 4567 0 0 1 1 10

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

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

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

24 1 23 4567 0 0 1 1 10 100101110111 The node numbers at the leaves converted to binary numbers.

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 child’s value.

26 67 33 1 Express 67 in decimal 1 (bin)

27 67 33 16 1 1 11 (bin)

28 67 33 16 8 1 1 0 011 (bin)

29 67 33 16 8 4 1 1 0 0 0011 (bin)

30 67 33 16 8 4 2 1 1 0 0 0 00011 (bin)

31 67 33 16 8 4 2 1 1 1 0 0 0 0 000011 (bin)

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.

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

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.

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

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.

37 a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 Let’s decode 10001

38 a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001

39 a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 c c

40 a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 c c

41 a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 c c

42 a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 ca

43 a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 ca

44 a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 ca

45 a b c 0 0 1 1 Symbol a: 00 Symbol b: 01 Symbol c: 1 10001 cab

46 Letters occurring in a paragraph and their frequency of occurrence. How can we encode these letters so that the resultant code is minimal?

47 b, 2h, 4g, 9a, 11 A list of nodes containing the letters and frequencies. The list is sorted by frequency.

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

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

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.

51 b, 2h, 4 g, 9 a, 11 *, 6 *, 15 Insert the parent node with its children in its sorted position in the list.

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

53 bh g a This tree is called a Huffman tree. Here it is shown with only the leaves labeled.

54 bh g a Label the edges with 0’s and 1’s as we did for the binary numbers. 0 0 0 1 1 1

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

56 bh g a Let’s decode 100011 0 0 0 1 1 1

57 bh g a 100011 0 0 0 1 1 1

58 bh g a 0 0 0 1 1 1

59 bh g a 0 0 0 1 1 1

60 bh g a 100011 We hit a leaf, print letter, 0 0 0 1 1 1 Resultant code: b

61 bh g a 100011 We hit a leaf, print letter & return to root. 0 0 0 1 1 1 Resultant code: b

62 bh g a 100011 We hit a leaf, print letter 0 0 0 1 1 1 Resultant code: ba

63 bh g a 100011 We hit a leaf, print letter & return to root. 0 0 0 1 1 1 Resultant code: ba

64 bh g a 100011 0 0 0 1 1 1 Resultant code: ba

65 bh g a 100011 We hit a leaf and print letter. 0 0 0 1 1 1 Resultant code: bag

66 bag : 100011 in Huffman code bag : 1100010 bag : 100011 in Huffman code bag : 1100010

67 bag : 100011 in Huffman code bag : 11000101100001 bag : 100011 in Huffman code bag : 11000101100001

68 bag : 100011 in Huffman code bag : 110001011000011100111 in ascii code bag : 100011 in Huffman code bag : 110001011000011100111 in ascii code

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.

70 12,b13,h 7,g 2,a The Huffman code is obtained from the binary by removing the leading 1.

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


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

Similar presentations


Ads by Google