Huffman coding
The output from Huffman's algorithm is a variable-length code table for encoding a source symbol (such as a character in a file).  The algorithm constructs this table based on the estimated probability or frequency of occurrence (weight) for each possible value of the source symbol.  As in other entropy encoding methods, more common symbols are generally represented using fewer bits than less common symbols.  Huffman's method can be efficiently implemented, finding a code in time linear to the number of input weights if these weights are sorted. Even though Huffman's method is optimal among methods encoding symbols separately, it is not always optimal among all compression methods - it is replaced with arithmetic coding or asymmetric numeral systems if a better compression ratio is required.