Presentation is loading. Please wait.

Presentation is loading. Please wait.

Huffman Coding The most for the least. Design Goals Encode messages parsimoniously No character code can be the prefix for another.

Similar presentations


Presentation on theme: "Huffman Coding The most for the least. Design Goals Encode messages parsimoniously No character code can be the prefix for another."— Presentation transcript:

1 Huffman Coding The most for the least

2 Design Goals Encode messages parsimoniously No character code can be the prefix for another

3 Requirements Message statistics Data structures to create and store new codes

4 Conventional Encoding Schemes Fixed length codes – E.g., Unicode, ASCII, rgb Sample data Optimal code length (in bits) is given by the entropy E: FreqLog2(Freq)-Product A0.13-2.94341650.382644 B0.27-1.88896870.510022 C0.35-1.51457320.530101 D0.17-2.55639330.434587 E0.08-3.64385620.291508 Entropy=>2.148862

5 Huffman Algorithm While (two or more trees in the Forest) – Find the two least weight trees i and j – Create a code Tree node whose left child is the root of tree i and right child is the root of tree j – Join the two least weight trees and replace tree i – Delete tree j

6 Graphical Solution (Step 1) A 0.13 B 0.27 C 0.35 D 0.17 E 0.08 0.21 E 0.08 A 0.13 B 0.27 C 0.35 D 0.17

7 Graphical Solution (Step 2) B 0.27 C 0.35 D 0.17 B 0.27 C 0.35 D 0.17 0.38 0.21 E 0.08 A 0.13 0.21 E 0.08 A 0.13

8 Graphical Solution (Step 3) B 0.27 C 0.35 D 0.17 0.38 D 0.17 0.38 B 0.27 C 0.35 0.62 0.21 E 0.08 A 0.13 0.21 E 0.08 A 0.13

9 Graphical Solution (Step 4) D 0.17 0.21 E 0.08 A 0.13 0.38 D 0.17 0.38 1.0 B 0.27 C 0.35 0.62 B 0.27 C 0.35 0.62 0.21 E 0.08 A 0.13

10 Interpreting the Code B 0.27 C 0.35 D 0.17 0.21 E 0.08 A 0.13 0.380.62 1.0 01 1 11 0 0 0 Symb ol CodeLengthFreqProd A 0113.13.39 B 102.27.54 C 112.35.70 D 002.17.34 E 0103.08.24 Avg.2.21

11 Data Structures ForestSourceCode Tree CursorweightRootCursorSymbolProbabilityLeafCursorleft childRight ChildRoot 10.1311A 11000 20.2722B 22000 30.3533C 33000 40.1744D 44000 50.0855E 55000

12 Step 1 ForestSourceCode Tree CursorweightRootCursorSymbolProbabilityLeafCursorleft childRight ChildRoot 10.1311A 11000 20.2722B 22000 30.3533C 33000 40.1744D 44000 50.0855E 55000

13 Step 2 ForestSourceCode Tree CursorweightRootCursorSymbolProbabilityLeafCursorleft childRight ChildRoot 10.2161A0.1311006 20.2722B 22000 30.3533C 33000 40.1744D 44000 5E0.0855006 6510

14 Step 3 ForestSourceCode Tree CursorweightRootCursorSymbolProbabilityLeafCursorleft childRight ChildRoot 10.3871A0.1311006 20.2722B 22000 30.3533C 33000 4D0.1744007 5E0.0855006 6517 7460

15 Step 4 ForestSourceCode Tree CursorweightRootCursorSymbolProbabilityLeafCursorleft childRight ChildRoot 10.3871A0.1311006 20.6282B0.2722008 3C0.3533008 4D0.1744007 5E0.0855006 6517 7460 8230

16 Step 5 ForestSourceCode Tree CursorweightRootCursorSymbolProbabilityLeafCursorleft childRight ChildRoot 1191A0.1311006 2B0.2722008 3C0.3533008 4D0.1744007 5E0.0855006 6517 7469 8239 9780


Download ppt "Huffman Coding The most for the least. Design Goals Encode messages parsimoniously No character code can be the prefix for another."

Similar presentations


Ads by Google