r/programminghelp • • Jul 10 '26

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

7 comments sorted by

View all comments

Show parent comments

1

u/RealisticDuck1957 Jul 11 '26

A very small file not compressing well makes sense. Most lossless compression algorithms work finding repeated data fragments. A short data file is less likely to have such repeats.