Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <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>
              
            
!

CSS

              
                #end
{
  font-size:18px;
}
              
            
!

JS

              
                
              
            
!
999px

Console