cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="container">
  <div class="col-sm-12 well">
    <h1 class="text-center">Huffman Coding</h1>
    <div class="well">
    <h3>What are Huffman Codes?</h3>
    <p>Huffman coding is a lossless data compression algorithm. The idea is to assign variable-length codes to input characters, lengths of the assigned codes are based on the frequencies of corresponding characters. The most frequent character gets the smallest code and the least frequent character gets the largest code.</p>
      <h4>There are mainly two major parts in Huffman Coding.<br></h4><p>
1) Build a Huffman Tree from input characters.<br>
2) Traverse the Huffman Tree and assign codes to characters.</p><br>
 <h4>Steps to build Huffman Tree</h4>
<p><strong>Forward Pass:</strong><br>
  1.Sort probabilities per symbol in descending order.<br>
  2.Combine lowest two probabilities.<br>
  3.Repeat step 2 until only two probabilities remain.<br>
  4.The last 2 probabilities must have sum=1.0<br>
 </p>
 <div class="table-responsive">
    <table class="table table-condensed table-hover">
      <thead>
      <tr>
        <th>Symbol</th>
        <th>Probability</th>
        <th>1</th>
        <th>2</th>
        <th>3</th>
        <th>4</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>a1</td>
        <td>0.4</td>
        <td>0.4</td>
        <td>0.4</td>
        <td>0.4</td>
        <td>0.6</td>
      </tr>
      <tr>
        <td>a2</td>
        <td>0.3</td>
        <td>0.3</td>
        <td>0.3</td>
        <td>0.3</td>
        <td>0.4</td>
      </tr>
      <tr>
        <td>a3</td>
        <td>0.1</td>
        <td>0.1</td>
        <td>0.2</td>
        <td>0.3</td>
      </tr>
      <tr>
        <td>a4</td>
        <td>0.1</td>
        <td>0.1</td>
        <td>0.1</td>
        
      </tr>
      <tr>
        <td>a5</td>
        <td>0.06</td>
        <td>0.1</td>
      </tr>
      <tr>
        <td>a6</td>
        <td>0.04</td>
      </tr>
     </tbody>
    </table>
   </div>
      
      
      
      <p><strong>Backward Pass:</strong><br>
  1.Assign Binary code (0,1) to last two values in your preferred order.<br>
  2.Gather bits going backward and form a code.<br>
  4.Note that code down.<br></p>
 <div class="table-responsive">
    <table class="table table-condensed table-hover">
      <thead>
      <tr>
        <th>Symbol</th>
        <th>Probability</th>
        <th>Code</th>
        <th>1</th>
        <th>2</th>
        <th>3</th>
        <th>4</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>a1</td>
        <td>0.4</td><td>1</td>
        <td>0.4</td>
        <td>0.4</td>
        <td>0.4</td>
        <td>0.6</td>
      </tr>
      <tr>
        <td>a2</td>
        <td>0.3</td><td>00</td>
        <td>0.3</td>
        <td>0.3</td>
        <td>0.3</td>
        <td>0.4</td>
      </tr>
      <tr>
        <td>a3</td>
        <td>0.1</td><td>011</td>
        <td>0.1</td>
        <td>0.2</td>
        <td>0.3</td>
      </tr>
      <tr>
        <td>a4</td>
        <td>0.1</td><td>0100</td>
        <td>0.1</td>
        <td>0.1</td>
        
      </tr>
      <tr>
        <td>a5</td>
        <td>0.06</td><td>01010</td>
        <td>0.1</td>
      </tr>
      <tr>
        <td>a6</td>        
        <td>0.04</td><td>01011</td>

      </tr>
     </tbody>
    </table>
   </div>
      
      
   <p id="end">The Codes generated in such a way are all unique.This is how Huffman Coding makes sure that there is no ambiguity when decoding the generated bit stream.</p>   
  
  
    
      
    </div>
            
          
!
999px
Loading ..................

Console