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.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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.

+ add another resource

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console