Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Data Compression Technique

40,193 views

Published on

It is very useful for storing a large file in a small storage disk.

Published in: Economy & Finance, Technology

Data Compression Technique

  1. 1. A Review of Data Compression Techniques Presented By IQxplorer
  2. 2. <ul><li>Data compression is the process of encoding data so that it takes less storage space or less transmission time than it would if it were not compressed. </li></ul><ul><li>Compression is possible because most real-world data is very redundant </li></ul>
  3. 3. <ul><li>Mainly two types of data Compression techniques are there. </li></ul><ul><ul><li>Loss less Compression. </li></ul></ul><ul><ul><ul><li>Useful in spreadsheets, text, executable program Compression. </li></ul></ul></ul><ul><ul><li>Lossy less Compression. </li></ul></ul><ul><ul><li>Compression of images, movies and sounds . </li></ul></ul>
  4. 4. <ul><li>Dictionary coders. </li></ul><ul><ul><li>Zip (file format). </li></ul></ul><ul><ul><li>Lempel Ziv. </li></ul></ul><ul><li>Entropy encoding. </li></ul><ul><ul><li>Huffman coding (simple entropy coding). </li></ul></ul><ul><li>Run-length encoding. </li></ul>
  5. 5. <ul><li>Dictionary-based algorithms do not encode single symbols as variable-length bit strings; they encode variable-length strings of symbols as single tokens. </li></ul><ul><li>The tokens form an index into a phrase dictionary. </li></ul><ul><li>If the tokens are smaller than the phrases they replace, compression occurs. </li></ul>
  6. 6. <ul><li>Static Dictionary. </li></ul><ul><li>Semi-Adaptive Dictionary . </li></ul><ul><li>Adaptive Dictionary . </li></ul><ul><ul><li>Lempel Ziv algorithms belong to this category of dictionary coders. The dictionary is being built in a single pass, while at the same time encoding the data. </li></ul></ul><ul><ul><li>The decoder can build up the dictionary in the same way as the encoder while decompressing the data. </li></ul></ul>
  7. 7. <ul><li>Using a English Dictionary the string: </li></ul><ul><li>“ A good example of how dictionary based compression works” </li></ul><ul><li>Gives : 1/1 822/3 674/4 1343/60 928/75 550/32 173/46 421/2 </li></ul><ul><li>Using the dictionary as lookup table, each word is coded as x/y, where, x gives the page no. and y gives the number of the word on that page. If the dictionary has 2,200 pages with less than 256 entries per page: Therefore x requires 12 bits and y requires 8 bits, i.e., 20 bits per word (2.5 bytes per word). Using ASCII coding the above string requires 48 bytes, whereas our encoding requires only 20 (<-2.5 * 8) bytes: 50% compression. </li></ul>
  8. 8. Lempel Ziv <ul><li>It is a family of algorithms, stemming from the two algorithms proposed by Jacob Ziv and Abraham Lempel in their landmark papers in 1977 and 1978. </li></ul>LZ77 LZ78 LZR LZH LZSS LZB LZFG LZC LZT LZMW LZW LZJ
  9. 9. <ul><li>It is An improved version of LZ78 algorithm . </li></ul><ul><li>Published by Terry Welch in 1984 . </li></ul><ul><li>A dictionary that is indexed by “codes” is used. The dictionary is assumed to be initialized with 256 entries (indexed with ASCII codes 0 through 255) representing the ASCII table. </li></ul>
  10. 10. <ul><li>W = NIL; </li></ul><ul><li>while (there is input){ </li></ul><ul><li>K = next symbol from input; </li></ul><ul><li>if (WK exists in the dictionary) { </li></ul><ul><li>W = WK; </li></ul><ul><li>} else { </li></ul><ul><li>output (index(W)); </li></ul><ul><li>add WK to the dictionary; </li></ul><ul><li>W = K; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  11. 11. The LZW Algorithm (Compression) Flow Chart START W= NULL IS EOF ? K=NEXT INPUT IS WK FOUND? W=WK OUTPUT INDEX OF W ADD WK TO DICTIONARY STOP W=K YES NO YES NO
  12. 12. <ul><li>Input string is </li></ul><ul><li>The Initial Dictionary </li></ul><ul><li>contains symbols like </li></ul><ul><li>a, b, c, d with their index values as 1, 2, 3, 4 respectively. </li></ul><ul><li>Now the input string is read from left to right. Starting from a. </li></ul>a b d c a d a c a 1 b 2 c 3 d 4
  13. 13. <ul><li>W = Null </li></ul><ul><li>K = a </li></ul><ul><li>WK = a </li></ul><ul><li>In the dictionary . </li></ul>K a b d c a d a c a 1 b 2 c 3 d 4
  14. 14. <ul><li>K = b. </li></ul><ul><li>WK = ab </li></ul><ul><li>is not in the dictionary. </li></ul><ul><li>Add WK to dictionary </li></ul><ul><li>Output code for a. </li></ul><ul><li>Set W = b </li></ul>K a b d c a d a c 1 ab 5 a 1 b 2 c 3 d 4
  15. 15. <ul><li>K = d </li></ul><ul><li>WK = bd </li></ul><ul><li>Not in the dictionary. </li></ul><ul><li>Add bd to dictionary. </li></ul><ul><li>Output code b </li></ul><ul><li>Set W = d </li></ul>K a b d c a d a c 1 2 ab 5 a 1 b 2 c 3 d 4 bd 6
  16. 16. <ul><li>K = a </li></ul><ul><li>WK = da </li></ul><ul><li>not in the dictionary. </li></ul><ul><li>Add it to dictionary. </li></ul><ul><li>Output code d </li></ul><ul><li>Set W = a </li></ul>K a b d a b d a c 1 2 4 ab 5 a 1 b 2 c 3 d 4 bd 6 da 7
  17. 17. <ul><li>K = b </li></ul><ul><li>WK = ab </li></ul><ul><li>It is in the dictionary. </li></ul>K a b d a b d a c 1 2 4 ab 5 a 1 b 2 c 3 d 4 bd 6 da 7
  18. 18. <ul><li>K = d </li></ul><ul><li>WK = abd </li></ul><ul><li>Not in the dictionary. </li></ul><ul><li>Add W to the dictionary. </li></ul><ul><li>Output code for W. </li></ul><ul><li>Set W = d </li></ul>K a b d a b d a c 1 2 4 5 ab 5 a 1 b 2 c 3 d 4 bd 6 da 7 abd 8
  19. 19. The LZW Algorithm (Compression) Example <ul><li>K = a </li></ul><ul><li>WK = da </li></ul><ul><li>In the dictionary. </li></ul>K a b d a b d a c 1 2 4 5 ab 5 a 1 b 2 c 3 d 4 bd 6 da 7 abd 8
  20. 20. The LZW Algorithm (Compression) Example <ul><li>K = c </li></ul><ul><li>WK = dac </li></ul><ul><li>Not in the dictionary. </li></ul><ul><li>Add WK to the dictionary. </li></ul><ul><li>Output code for W. </li></ul><ul><li>Set W = c </li></ul><ul><li>No input left so output code for W. </li></ul>K a b d a b d a c 1 2 4 5 ab 5 a 1 b 2 c 3 d 4 bd 6 da 7 abd 8 7 dac 9
  21. 21. The LZW Algorithm (Compression) Example <ul><li>The final output string is </li></ul><ul><li>1 2 4 5 7 3 </li></ul><ul><li>Stop. </li></ul>K c a d b a d b a 1 2 4 5 5 ab 4 d 3 c 2 b 1 a 6 bd 7 da 8 abd 7 9 dac 3
  22. 22. LZW Decompression Algorithm read a character k; output k; w = k; while ( read a character k ) /* k could be a character or a code. */ { entry = dictionary entry for k; output entry; add w + entry[0] to dictionary; w = entry; }
  23. 23. LZW Decompression Algorithm Flow Chart START Output K IS EOF ? K=NEXT INPUT ENTRY=DICTIONARY INDEX (K) ADD W+ENTRY[0] TO DICTIONARY STOP W=ENTRY K=INPUT W=K YES NO Output ENTRY
  24. 24. The LZW Algorithm (Decompression) Example <ul><li>K = 1 </li></ul><ul><li>Out put K (i.e. a) </li></ul><ul><li>W = K </li></ul>K 1 2 4 5 4 d 3 c 2 b 1 a 7 3 a
  25. 25. The LZW Algorithm (Decompression) Example <ul><li>K = 2 </li></ul><ul><li>entry = b </li></ul><ul><li>Output entry </li></ul><ul><li>Add W + entry[0] to dictionary </li></ul><ul><li>W = entry[0] (i.e. b) </li></ul>K 1 2 4 5 4 d 3 c 2 b 1 a 7 3 a b 5 ab
  26. 26. The LZW Algorithm (Decompression) Example <ul><li>K = 4 </li></ul><ul><li>entry = d </li></ul><ul><li>Output entry </li></ul><ul><li>Add W + entry[0] to dictionary </li></ul><ul><li>W = entry[0] (i.e. d) </li></ul>K 1 2 4 5 4 d 3 c 2 b 1 a 7 3 a b 5 ab 6 bd d
  27. 27. The LZW Algorithm (Decompression) Example <ul><li>K = 5 </li></ul><ul><li>entry = ab </li></ul><ul><li>Output entry </li></ul><ul><li>Add W + entry[0] to dictionary </li></ul><ul><li>W = entry[0] (i.e. a) </li></ul>K 1 2 4 5 4 d 3 c 2 b 1 a 7 3 a b 5 ab 6 bd d a b 7 da
  28. 28. The LZW Algorithm (Decompression) Example <ul><li>K = 7 </li></ul><ul><li>entry = da </li></ul><ul><li>Output entry </li></ul><ul><li>Add W + entry[0] to dictionary </li></ul><ul><li>W = entry[0] (i.e. d) </li></ul>K 1 2 4 5 4 d 3 c 2 b 1 a 7 3 a b 5 ab 6 bd d a b 7 da d a 8 abd
  29. 29. The LZW Algorithm (Decompression) Example <ul><li>K = 3 </li></ul><ul><li>entry = c </li></ul><ul><li>Output entry </li></ul><ul><li>Add W + entry[0] to dictionary </li></ul><ul><li>W = entry[0] (i.e. c) </li></ul>K 1 2 4 5 4 d 3 c 2 b 1 a 7 3 a b 5 ab 6 bd d a b 7 da d a 8 abd c 9 dac
  30. 30. <ul><li>As LZW is adaptive dictionary coding no need to transfer the dictionary explicitly. </li></ul><ul><li>It will be created at the decoder side. </li></ul><ul><li>LZW can be made really fast, it grabs a fixed number of bits from input, so bit parsing is very easy, and table look up is automatic. </li></ul>
  31. 31. Problems with the encoder <ul><li>What if we run out of space? </li></ul><ul><ul><li>Keep track of unused entries and use LRU (Last Recently Used). </li></ul></ul><ul><ul><li>Monitor compression performance and flush dictionary when performance is poor. </li></ul></ul>
  32. 32. <ul><li>LZW has given new dimensions for the development of new compression techniques. </li></ul><ul><li>It has been implemented in well known compression format like Acrobat PDF and many other types of compression packages. </li></ul><ul><li>In combination with other compression techniques many other different compression techniques are developed like LZMS. </li></ul>
  33. 33. <ul><li>[1] http://www.bambooweb.com/articles/d/a/Data_Compression.html </li></ul><ul><li>[2] http://tuxtina.de/files/seminar/LempelZivReport.pdf </li></ul><ul><li>[3] BELL, T. C., CLEARY, J. G., AND WITTEN, I. H. Text Compression . Prentice Hall, Upper Sadle River, NJ, 1990. </li></ul><ul><li>[4] http://www.cs.cf.ac.uk/Dave/Multimedia/node214.html </li></ul><ul><li>[5] http://download.cdsoft.co.uk/tutorials/rlecompression/Run-Length Encoding (RLE) Tutorial.htm </li></ul><ul><li>[6] David Salomon, Data Compression The Complete Reference, Second Edition . Springer-Verlac, New York, Inc, 2001 reprint. </li></ul><ul><li>[7] http://www.programmersheaven.com/2/Art_Huffman_p1.htm </li></ul><ul><li>[8] http://www.programmersheaven.com/2/Art_Huffman_p2.htm </li></ul><ul><li>[9] Khalid Sayood, Introduction to Data Compression Second Edition, Chapter 5, pp. 137-157, Harcourt India Private Limited. </li></ul>

×