0

WYS*WYGWYS*WYSWYSG

When compressed above string using LZW algorithm it gave an output codes as below.

87 89 83 42 256 71 256 258 262 262 71

So you can see size of output codes bigger than that of the string.now I need to know How should I store it in a file?

Thank you.

user7185
  • 3
  • 4
  • With your example... You are not comparing the same output type as input type If you convert your original string to 8 bit bytes codes. FROM : WYS*WYGWYS*WYSWYSG BYTE CODES are: 87 89 83 42 87 89 71 87 89 83 42 87 89 83 87 89 83 71 Your output values are 9 bits each. not 8bits. Bitp-acking your output makes the new output shorter. 87 89 83 42 256 71 256 258 262 262 71 Original is 18 bytes long. (18 * 8 bites each = 144 bits ) New output has 11 symbols 11 *9 bits each = 99 bits (12.375 bytes Packed. that takes 13 bytes) The question is do you understand bit-packing? – Phillip Williams May 26 '20 at 01:19
  • Thank you for the explanation, I understand it now,but why (compression ratio (18/13= 1.38 ) way lower even original string consists with more repetitive data.isn't it supposed to give a high ratio which is more than 1.38 ? – user7185 May 26 '20 at 10:30
  • LZW is a greedy algorithm building patterns one at a time. It dos not look ahead to see if there are longer strings or which pattern repeat the most. It is dynamic in nature, trying to guess that something that occurred might occur a little longer. For example: If LZW is given a long string of X's IE: XXXXXXXXXXXXXXXXXX the build up of patterns found in order would be something like X X XX XXX XXXX XXXX XXX . At each new pattern LZW only considers 1 extra character forward, and its past of seen patterns. LZW has no real look ahead, to help optimize the patterns found – Phillip Williams May 26 '20 at 12:01
  • Thank you again for the further explanation – user7185 May 26 '20 at 13:53

0 Answers0