Sitemap
Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.

Member-only story

Data Compression (Part 3)

--

Huffman Encoding

Please give a read to Part 2 here

Now, let’s understand a standard compression technique known as “Huffman encoding” which further reduces the length of our text.

While reducing length, we kept one thing in mind i.e “No binary is a prefix of another”.

And for this, we gave all binary an equal length since a binary can be a prefix of another only if its length is shorter than that of another one.

But what if it is possible to assign binary formats without giving equal length to all and still no binary format is a prefix of another ??? 🤔

If this is possible, the binary format of our text will further be reduced.

Huffman comes for rescue here.

Lets understand a basic thing first before going deep into this:

Press enter or click to view image in full size

We have two nodes in this tree and we allocate 0 on the left edge and 1 on the right edge.

So node “A” can be given binary 0

--

--

Mridul Singh
Mridul Singh

Written by Mridul Singh

Software engineer writing about AI agents, production systems & what breaks in the real world. Building along the way. Paid collabs - send2mridul@gmail.com

Stackademic
Stackademic

Published in Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.