---
title: "Huffman’s algorithm in Data Structure ?"  
description: "Huffman’s algorithm in Data Structure ?"  
author: "Anonymous User"  
published: 2019-09-07  
updated: 2019-09-07  
canonical: https://www.mindstick.com/forum/95342/huffman-s-algorithm-in-data-structure  
category: "c#"  
tags: ["c#", "data structure"]  
reading_time: 2 minutes  

---

# Huffman’s algorithm in Data Structure ?

Please [describe in brief](https://www.mindstick.com/forum/157676/describe-in-brief-the-goal-of-i-o-software-in-operating-systems).

## Replies

### Reply by Anonymous User

The **Huffman’s algorithm** is used for creating extended binary trees that have minimum weighted path lengths from the given weights. That makes use of a table that contains the frequency of occurrence for each data element.

![Huffman’s algorithm in Data Structure ?](https://www.mindstick.com/mindstickforums/2d138ac2-e87d-4227-90d5-f8e713477b00/images/57cab0a1-a2fe-4a66-9226-96f91971648e.png)\

The Huffman algorithm or Huffman coding is an entropy encoding algorithm.

This is used widely for data compression (like WinZip Compression-WinZip doesn’t use it but!)

The Huffman coding is used in JPEG compression.

The primary idea behind Huffman coding is to encode the most common characters using shorter strings of bits than those used for less common source characters.

That works by creating a binary tree stored in an array.

You also need to know the external path length (sum of all paths from the root to external node) and internal path length (sum of all paths from root to internal node).

Some important steps for the Huffman Algorithm

- **First Step**:- Create a leaf node for each character. Attach the character and its weight or frequency of occurrence to the priority queue.
- **Second Step**: Repeat Steps 3 to 5 while the total number of nodes in the queue is greater than 1
- **Third Step**: Remove two nodes that have the lowest weight (or highest priority)
- **Fourth Step**: Create a new internal node by merging these two nodes as children and with weight equal to the sum of the two nodes' weights.
- **Fifth Step**: Add the newly created node to the queue.


---

Original Source: https://www.mindstick.com/forum/95342/huffman-s-algorithm-in-data-structure

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
