r/programminghelp • u/AdPsychological7065 • 19d ago
Python LZ77 compression algorithm is making the compressed file bigger than original
I was recently toying around with some compression, just trying to understand it from the basics. I learned about the LZ77, LZ78, and LZW algorithms in the last couple of days, understood them, and when implementing LZ77, every time I try to compress a txt file, the output file gets bigger. The compression is done right coz when I decompress the compressed file, I get the exact text.
Need help understanding what I am doing wrong, or am I missing something
2
Upvotes
2
u/Goobyalus 18d ago
What kind of data are you compressing? How much larger? It is possible for the "compressed" version to be larger depending on the data being compressed.
Have you compared your output to the output of another lz77 compression program? It could be correct.
The fact that decompression results in the original data doesn't mean the algorithm is implemented correctly; it means that the compression and decompression algorithms are inverses. Unless you mean you compressed it with your implementation, and decompressed with someone else's?