code/compression/src/lossless_compression/lempel_ziv_welch/README.md
The Lempel-Ziv-Welch (LZW) algorithm is a dictionary-based lossless compressor. The algorithm uses a dictionary to map a sequence of symbols into codes which take up less space. LZW performs especially well on files with frequent repetitive sequences.
Example: the input "ToBeOrNotToBeABanana" (length of 20) would be encoded in 17.
[T][o][B][e][O][r][N][o][t][To][Be][A][B][a][n][an][a]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
The brackets separate the values (e.g. [To] is encoded as one value). The LZW algorithm replaces the second occurences of To, Be, and an with one value, eliminating data redundancy.
Note that there is no need to store the dictionary because the LZW uncompression process reconstructs the dictionary as it goes along.
Image credits: https://slideplayer.com/slide/5049613/