Sunday, January 1, 2017

File Compression

File Compression

ZIP files are very handy invention. It reduces the overall number of bits and bytes in a file so it can be transmitted faster and takes less space.
What file compression does is that it simply gets rid of the redundancy. For eg:-
Let's take example of J.F.K's quote:-
Ask not what your country can do for you - ask what you can do for your country.

Here there are:-

  • 17 - words
  • 61 - letters
  • 16 - spaces
  • 1 - dash
  • 1 - period
  • 79 - total memory units

Here "ask", "what", "your", "country", "can", "do", "for" and "you" appear two times.
Here's what LZ adaptive dictionary-based algorithm does. It indexes number to redundant words.
1.ask
2.what
3.your
4.country
5.can
6.do
7.for
8.you
Our sentence now is "1 not 2 3 4 5 6 7 8 - 1 2 8 5 6 7 3 4"
Here indexing takes 37 byte and sentence takes 37 byte taking overall 74 byte. It's not much but in reality the files take much more space and there is much more redundancy.

Here we take a look at repeated words but compression program sees it different. It doesn't know about separate words, it looks for patterns.
Here
1. "ask "
2. "what"
3. "you"
4. "r country"
5. " can do for you"
are repeated and the sentence can be made using these fragments.
1 not 2345 - 12354
Which decreased the total file size to 59 units

No comments:

Post a Comment