Huffman Text Compression Tool using Tree and Priority Queue
What Is Huffman Coding? Huffman coding is a powerful algorithm for compressing data without losing information, also called "lossless compression". It replaces frequently recurring characters with shorter binary codes, and rare characters with longer ones, making files and data smaller in size. This technique is used in many modern compression formats. Why Use Huffman Coding? Traditional encoding (like ASCII) gives every character the same number of bits (usually 8). But if some characters appear way more often, there's an opportunity for optimisation. Huffman coding finds the most efficient way to assign variable-length codes so the overall data size is minimised. How Does Huffman Coding Work? Let’s break the process down: 1. Frequency Analysis First, count the frequency of each character in the text. More frequent characters are “cheaper” to encode. Example: For the string ABRACADABRA: A: 5 B: 2 R: 2 C: 1 D: 1 2. Initialise Priority Queue Put each character and its fr...