15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

440<br />

Lossless Data Compression Algorithms<br />

The LZ77 algorithm<br />

The LZ77 algorithm was created by two computer scientists — Abraham<br />

Lempel and Jakob Ziv, who first published their algorithm in 1977 (hence the<br />

name LZ77). The LZ77 algorithm works by looking <strong>for</strong> repetitive data. Rather<br />

than storing this repetitive data in a separate dictionary, the LZ77 remembers<br />

the location of this data in the original file.<br />

When the algorithm finds this same data stored somewhere else, it removes<br />

this data (compressing the overall in<strong>for</strong>mation) and substitutes a pointer to<br />

the previously recognized data, as shown in Figure 4-3.<br />

Figure 4-3:<br />

The LZ77<br />

algorithm<br />

replaces<br />

redundant<br />

data with<br />

pointers.<br />

See Dick Jane<br />

Because pointers take up less space than the actual data, the LZ77 algorithm<br />

compresses in<strong>for</strong>mation. The more redundant data, the more efficient<br />

the compression.<br />

The LZ78 algorithm<br />

One problem with the LZ77 algorithm is that it stores redundant data<br />

directly in the compressed data itself. To improve compression, the same<br />

computer scientists developed a variation of the LZ77 algorithm — the LZ78<br />

algorithm.<br />

The LZ78 algorithm removes all redundant data and stores it in a separate<br />

dictionary. Then the algorithm substitutes the redundant data with much<br />

smaller codes stored in the dictionary. By removing this data, the LZ78<br />

algorithm can compress data even further than the LZ77 algorithm.<br />

To uncompress this data, the computer follows each code to the dictionary<br />

to retrieve the appropriate data chunk.<br />

The LZW algorithm<br />

The LZW algorithm gets its name from Terry Welch, who created his own variation<br />

of the LZ78 algorithm, dubbed the LZW algorithm. The LZW algorithm<br />

works by creating a dictionary, just like the LZ78 algorithm. But whereas the

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!