Skip to main content

Posts

Showing posts with the label Huffman

Huffman Coding

  Huffman coding is a lossless data compression algorithm named after its inventor, David A. Huffman. It is a variable-length prefix coding algorithm, which means that it assigns shorter codes to the more frequently occurring symbols in a dataset and longer codes to the less frequently occurring symbols. This results in a smaller overall size of the compressed data. How it Works The Huffman coding algorithm starts by building a frequency table of all the symbols in the dataset, which shows the number of occurrences of each symbol. Then, it creates a binary tree with each symbol represented by a leaf node. The parent node of two children represents the sum of their frequencies. The process continues until there is only one node left, which is the root of the tree. Each leaf node in the tree is assigned a unique binary code, where a 0 is assigned to the left child and a 1 is assigned to the right child. The code for each symbol is the path from the root of the tree to the correspo...