Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dr. O.Bushehrian ALGORITHM DESIGN HUFFMAN CODE. Fixed length code a: 00b: 01c: 11 Given this code, if our file is ababcbbbc our encoding is 000100011101010111.

Similar presentations


Presentation on theme: "Dr. O.Bushehrian ALGORITHM DESIGN HUFFMAN CODE. Fixed length code a: 00b: 01c: 11 Given this code, if our file is ababcbbbc our encoding is 000100011101010111."— Presentation transcript:

1 Dr. O.Bushehrian ALGORITHM DESIGN HUFFMAN CODE

2 Fixed length code a: 00b: 01c: 11 Given this code, if our file is ababcbbbc our encoding is 000100011101010111 Variable length code: a: 01b: 1c:00 our encoding is 0110110011100

3 Prefix Codes In a prefix code no codeword for one character constitutes the beginning of the codeword for another character a: 0 b: 10 c: 11

4 Suppose our character set is {a,b,c,d,e,f} and each character appears in the file the number of times indicated in The following table. This table also shows three different codes we could use to encode the file. CharacterFrequencyC1(Fixed-length)C2(Variable-length)C3(Huffman) a1600000111 b5001000000001 c120100001001 d170110110 e 100000010000 f25101101

5 C1 code tree: f: 25 d: 17 1 0 0 a: 16 e: 10 b: 5 c: 12 1 0 0 0 1 1 1

6 C2 code tree: 1 a: 16 d: 17 f: 25 c: 12 b: 5e: 10 0 1 1 1 1 0 0 0 0

7 A Simple Ex: a: 4b: 5c: 6d: 7 ‘ab’:9 b:5 a:4

8 Huffman's Algorithm for (i = 1; i < = n-1; i++) { remove (Q, p); remove (Q, q); r = new nodetype; r.left = p; r.right = q; r.frequency = p.frequency + q.frequency; insert (Q, r); }

9 The state of the subtrees, constructed by Huffman's algorithm, after each pass through the for-i loop. The first tree is the state before the loop is entered.


Download ppt "Dr. O.Bushehrian ALGORITHM DESIGN HUFFMAN CODE. Fixed length code a: 00b: 01c: 11 Given this code, if our file is ababcbbbc our encoding is 000100011101010111."

Similar presentations


Ads by Google