+ All Categories
Home > Documents > Dr. O.Bushehrian ALGORITHM DESIGN HUFFMAN CODE. Fixed length code a: 00b: 01c: 11 Given this code,...

Dr. O.Bushehrian ALGORITHM DESIGN HUFFMAN CODE. Fixed length code a: 00b: 01c: 11 Given this code,...

Date post: 29-Dec-2015
Category:
Upload: cory-davidson
View: 214 times
Download: 0 times
Share this document with a friend
Popular Tags:
9
Dr. O.Bushehrian ALGORITHM DESIGN HUFFMAN CODE
Transcript

Dr. O.Bushehrian

ALGORITHM DESIGN

HUFFMAN CODE

Fixed length codea: 00 b: 01 c: 11

Given this code, if our file isababcbbbc

our encoding is000100011101010111

Variable length code:a: 01 b: 1 c:00

our encoding is0110110011100

Prefix Codes

In a prefix code no codeword for one character constitutes the beginning of the codeword for another character

a: 0b: 10c: 11

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.

Character

Frequency

C1(Fixed-length)

C2(Variable-length)

C3(Huffman)

a 16 000 001 11

b 5 001 00000 0001

c 12 010 0001 001

d 17 011 01 10

e 10 100 00001 0000

f 25 101 1 01

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

C2 code tree:

1

a: 16

d: 17

f: 25

c: 12

b: 5e: 10

0

1 1

1

1

0

0 0

0

A Simple Ex:a: 4 b: 5 c: 6 d: 7

‘ab’:9

b:5

a:4

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);

}

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.


Recommended