Introduction

I’m going to show you how to use an online tool I call Prefix-free Pipes to give students and intuitive understanding of what binary codes are, and how they can be encoded, decoded, and even visualized. In particular, we’ll be looking at Huffman encodings. What are Huffman encodings?

Huffman encodings are a scheme of encoding text as binary digits subject to the rule that “there is no whole code in the system that is a prefix of any other code word in the system.” (Wikipedia)

If that made no sense, let’s play the game, develop an intuition and try that explanation again later.

The game: secret decoder

No really, what are Huffman encodings?

They’re a scheme to encode data digitally while also compressing it so that is uses fewer bits to transmit. How it actually works, it what we’ll find out as we play the game. Let’s dive in.

The game works like this. You receive a message from your friend containing a URL with a secret code attached. Clicking on the link will take you to the secret decoder. The message is represented by a binary code that can be displayed in a O’s and 1’s, or L’s and R’s.

And it can be decoded by this series of pipes. No really!

The secret code can be decoded with this series of pipes. No, really. Watch.

We start at the top of the pipe system if the next character of the code is a an L, we go left. If it’s an R, we go right. When we hit a letter, we go back to the top.

Visit the code creator to create a code

Click on “write a message”, then start typing. “No, but I’ve seen Night at the Museum.” or just click here click here to have it populated for you.

Pay attention to the number of bits we created in the code. (A bit is a binary digit…)

We have 203 bits in total.

The letter “N” is represented by LLL (Left-Left-Left) and takes up three bits.

The letter “o” is represented by RL (Right-Left) and takes up 2 bits.

So the code for “N” is longer than “o” in the code.

But wait. There are 2 “N” characters in the message, but only one “o”. If we swap the “N” with the “o”, the “N” will be a shorter trip from the top, and we can save one bit. Watch how the bits reduce from 203 to 202.

We can save our partner some effort by reducing the number of clicks required to solve the code.

Click “Share” to copy it. And email it to a friend. Be considerate, and have fun!