Docsity

Huffman Coding Correctness and Complexity, Study notes of Design and Analysis of Algorithms

Toggle sidebar
bg1
1
Huffman Codes
Chapter 16
4/30/09 CS380 Algorithm Design a nd Analysis
2
Data Compression
•Huffman codes are used for data
compression. The motivations for data
compression are obvious: reducing time to
transmit large files, and reducing the space
required to store them on disk or tape.
•The code was devised by Huffman as part of
a course assignment at MIT in the early
1950s.
4/30/09 CS380 Algorithm Design a nd Analysis
3
Goal
•Huffman coding is a technique for assigning
binary sequences to elements of an
alphabet.
•The goal of an optimal code is to assign the
minimum number of bits to each symbol
(letter) in the alphabet.
4/30/09 CS380 Algorithm Design a nd Analysis
pf3
pf4
pf5

Partial preview of the text

Download Huffman Coding Correctness and Complexity and more Study notes Design and Analysis of Algorithms in PDF only on Docsity!

1

Huffman Codes

Chapter 16 4/30/09 CS380 Algorithm Design and Analysis 2

Data Compression

  • Huffman codes are used for data compression. The motivations for data compression are obvious: reducing time to transmit large files, and reducing the space required to store them on disk or tape.
  • The code was devised by Huffman as part of a course assignment at MIT in the early 1950s. 4/30/09 CS380 Algorithm Design and Analysis

Goal

  • Huffman coding is a technique for assigning binary sequences to elements of an alphabet.
  • The goal of an optimal code is to assign the minimum number of bits to each symbol (letter) in the alphabet.

4

File Size

  • Suppose that you have a file of 100K characters.
  • To keep the example simple, suppose that each character is one of the 8 letters from a through h.
  • How much space is required to store this file? 4/30/09 CS380 Algorithm Design and Analysis 5

File Size

  • Can we do better?
  • Suppose that we have more information about the file: the frequency with which each character appears.
  • Use a variable length code instead of a fixed length code
  • Use fewer bits to store common characters 4/30/09 CS380 Algorithm Design and Analysis

Example

A B C D E F G H Frequency 45K 13K 12K 16K 9K 5K 0K 0K Fixed length code 000 001 010 011 100 101 110 11 Variable length code^1

  • How much space will the file stored using variable-length code take?
  • What is the saving or compression ration?

10

Variable Length Code Tree

4/30/09 CS380 Algorithm Design and Analysis 11

HUFFMAN(C)

  • C is a set of n characters and each c in C has a frequency 4/30/09 CS380 Algorithm Design and Analysis

Example

  • Find the optimal code for the following Character Freq Fixed Code Bits Variable code Bits A 10 000 30 E 15 001 45 I 12 010 36 S 3 011 9 T 4 100 12 SP 13 101 39 NL 1 110 3

13

Entropy

  • Entropy is a measure of the amount of uncertainty or randomness associated with a random variable; that is, it is a measure of the amount of information on the average required to describe the variable.
  • In compression, entropy is a measure of how much information is actually in the text being compressed 4/30/09 CS380 Algorithm Design and Analysis p ( x )log 2 p ( x ) x i

Example

  • What is the entropy for the previous example?