day23sup - COP 3503 Computer Science II CLASS NOTES - DAY...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 3503 – Computer Science II CLASS NOTES - DAY #23 Supplement Example: Suppose that we have a four letter alphabet consisting of a, b, c, and d, and e only. To encode four letters requires 2 bits. Suppose that these are assigned as follows: a = 00, b = 01, c = 10, and d = 11. Now suppose that we have a sentence of these letters which is 15 characters long. This sentence will require 30 bits to encode. Suppose that we also have some information about the frequency of occurrence of each of our letters and know that “a” occurs most frequently, followed by b and so on. A Huffman coding tree is built as shown below with the most frequently occurring letters closest to the root. 0 1 1 0 1 Reading the new codes from the tree we have: a = 0, b = 10, c = 110, and d = 111. Now suppose our 15 character sentence contains 8 a’s, 4 b’s, 2 c’s, and 1 d. With the new code this sentence requires (8*1) + (4*2) + (2*3) + (1*3) bits = 8 + 8 + 6 + 3 = 25 bits. The original code required 30 bits so we have save (30- 25)/30 = 16%. We mentioned that the occurrence frequency of every “character” in the file which is to be compressed must be known prior to building the coding tree. This information might appear in a frequency array like the one shown below: Letter a b c d Frequency 8 4 2 1 Day 23 Supplement - 1 Huffman Coding Revisited 1 a 7 d b c
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Building a Huffman Coding Tree Let’s assume that the file to be compressed consists of alphabetic characters, like a text file. (Huffman’s coding algorithm can be used to compress a file of basically any type of object for which a frequency of occurrence can be established.)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

day23sup - COP 3503 Computer Science II CLASS NOTES - DAY...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online