.. _Huffman:
.. raw:: html
.. |--| unicode:: U+2013 .. en dash
.. |---| unicode:: U+2014 .. em dash, trimming surrounding whitespace
:trim:
.. odsalink:: AV/Binary/huffmanCON.css
.. This file is part of the OpenDSA eTextbook project. See
.. http://opendsa.org for more details.
.. Copyright (c) 2012-2020 by the OpenDSA Project Contributors, and
.. distributed under an MIT open source license.
.. avmetadata::
:author: Cliff Shaffer
.. odsalink:: DataStructures/huffman.css
==============
Huffman Coding
==============
Huffman Coding
--------------
Coding
~~~~~~
* ASCII codes are fixed length (7 + 1 bits)
* In general, $n$ bits can store $2^n$ codes
* An alternative is variable-length coding
* The relative frequencies for eight selected letters.
.. math::
\begin{array}{|c|cccccccc|}
\hline
\textrm Letter & C & D & E & K & L & M & U & Z\\
\textrm Frequency & 32 & 42 & 120 & 7 & 42 & 24 & 37 & 2\\
\hline
\end{array}
Huffman Coding Trees
~~~~~~~~~~~~~~~~~~~~
.. inlineav:: huffmanBuildCON ss
:long_name: Huffman Coding Tree Slideshow: Build
:output: show
Assigning Codes
~~~~~~~~~~~~~~~
.. inlineav:: huffmanLabelCON ss
:long_name: Huffman Coding Tree Slideshow: Label Edges
:output: show
Using Codes
~~~~~~~~~~~
.. inlineav:: huffmanCodesCON ss
:long_name: Huffman Coding Tree Slideshow: Setting Codes
:output: show
Decoding
~~~~~~~~
.. inlineav:: huffmanDecodeCON ss
:long_name: Huffman Coding Tree Slideshow: Decoding
:output: show
.. odsascript:: DataStructures/huffman.js
.. odsascript:: AV/Binary/huffmanBuildCON.js
.. odsascript:: AV/Binary/huffmanLabelCON.js
.. odsascript:: AV/Binary/huffmanCodesCON.js
.. odsascript:: AV/Binary/huffmanDecodeCON.js