The development of **data compression** algorithms for a variety of data can be divided into two phases. The first phase is usually referred to as **modeling**. In this phase we try to extract information about any redundancy that exists in the data and describe the redundancy in the form of a model. The second phase is called **coding**. A description of the model and a “description” of how the data differ from the model are encoded, generally using a **binary alphabet**. The difference between the data and the model is often referred to as the residual.

**Suppose we have the following sequence:**

a/barayaran/barray/bran/bfar/bfaar/bfaaar/baway

which is typical of all sequences generated by a source. Notice that the sequence is made up of eight different symbols. In order to represent eight symbols, we need to use 3 bits per symbol. Suppose instead we used the code shown in Table 1.1. Notice that we have assigned a codeword with only a single bit to the symbol that occurs most often, and correspondingly longer codewords to symbols that occur less often. If we substitute the codes for each symbol, we will use 106 bits to encode the entire sequence. As there are 41 symbols in the sequence, this works out to approximately 258 bits per symbol. This means we have obtained a compression ratio of 1.16:1.

T A B L E 1 . 1 | A code with codewords of varying length. | |

a | 1 | |

n | 001 | |

b | 01100 | |

f | 0100 | |

n | 0111 | |

r | 000 | |

w | 01101 | |

y | 0101 |

When dealing with text, along with statistical redundancy, we also see redundancy in the form of words that repeat often. We can take advantage of this form of redundancy by constructing a list of these words and then represent them by their position in the list. This type of compression scheme is called a** dictionary compression scheme**.

**Modeling**

If we use a an automotive metaphor for **data compression**, coding would be the wheels, but **modeling **would be the engine. Regardless of the efficiency of the coder, if it doesn’t have a model feeding it good probabilities, it won’t compress data

**Lossless data compression** is generally implemented using one of two different types of modeling: statistical or dictionary-based. Statistical modeling reads in and encodes a single symbol at a time using the probability of that character’s appearance. Dictionary-based modeling uses a single code to replace strings of symbols. In dictionary-based modeling, the coding problem is reduced in significance, leaving the model supremely important

**Statistical Modeling**

The simplest forms of statistical modeling use a static table of probabilities. In the earliest days of information theory, the CPU cost of analyzing data and building a Huffman tree was considered significant, so it wasn’t frequently performed. Instead, representative blocks of data were analyzed once, giving a table of character-frequency counts. **Huffman encoding/decoding trees** were then built and stored. Compression programs had access to this static model and would compress data using it

**Dictionary Schemes**

Statistical models generally encode a single symbol at a time— reading it in, calculating a probability, then outputting a single code. A dictionary-based compression scheme uses a different concept. It reads in input data and looks for groups of symbols that appear in a dictionary. If a string match is found, a pointer or index into the dictionary can be output instead of the code for the symbol. The longer the match, the better the compression ratio

**Coding**

Once Information Theory had advanced to where the number of bits of information in a symbol could be determined, the next step was to develop new methods for encoding information. To compress data, we need to encode symbols with exactly the number of bits of information the symbol contains. If the character ‘e’ only gives us four bits of information, then it should be coded with exactly four bits. If ‘x’ contains twelve bits, it should be coded with twelve bits.