10182

# Huffman Coding

Huffman coding is a method of data compression that assigns shorter code words to those characters that occur with higher probability and longer code words to those characters that occur with lower probability. A Huffman code is an example of a prefix code—no character has a code word that is a prefix of another character's code word. In the "show steps" mode, this Demonstration illustrates the step-by-step procedure for finding the Huffman code for a set of characters with given probabilities. The "decode" mode gives the user an opportunity to decipher strings that have been encoded using the Huffman code.

### DETAILS

To find the Huffman code for a given set of characters and probabilities, the characters are sorted by increasing probability (weight). The character with smallest probability is given a 0 and the character with the second smallest probability is given a 1. The two characters are concatenated, and their probabilities added. This new string and its weight then take the place of both characters and their weights. At each stage the newly assigned 0's and 1's are prepended to the code strings already assigned to each letter in the corresponding string. This procedure is iterated until there is only one string with weight 1 (see the thumbnail and snapshots 1 and 2).
Four different codes are provided. All use the six characters A–F, but have different probabilities assigned to the characters. In the decode mode, nine fixed words are included to make it easy to illustrate the different code words that the different codes give. The random word option will give a random string of length between 3 and 7, inclusive.
Use the popup menus to enter a "guess" for decoding a string.

### PERMANENT CITATION

 Share: Embed Interactive Demonstration New! Just copy and paste this snippet of JavaScript code into your website or blog to put the live Demonstration on your site. More details » Download Demonstration as CDF » Download Author Code »(preview ») Files require Wolfram CDF Player or Mathematica.

#### Related Topics

 RELATED RESOURCES
 The #1 tool for creating Demonstrations and anything technical. Explore anything with the first computational knowledge engine. The web's most extensive mathematics resource. An app for every course—right in the palm of your hand. Read our views on math,science, and technology. The format that makes Demonstrations (and any information) easy to share and interact with. Programs & resources for educators, schools & students. Join the initiative for modernizing math education. Walk through homework problems one step at a time, with hints to help along the way. Unlimited random practice problems and answers with built-in Step-by-step solutions. Practice online or make a printable study sheet. Knowledge-based programming for everyone.