When talking about Agile software development, I like using the analogy of tightrope walking. I think it’s a good metaphor to describe the challenges normally encountered when developing software and the inspect&adapt nature of Agile.

The similarities between the two worlds are many:

  • Like software development, tightrope walking is difficult;


The Monty Hall problem is a probability puzzle that I just love because so fascinatingly counterintuitive.

The problem is simple:

Suppose you’re on a game show, and you’re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say n.1…


In Parts 18 of this series, I’ve shown how to build a Huffman compressor and decompressor.

I followed a strict test-driven approach: write a test, run the test and verify it fails, write the code, re-run the test and verify it passes, refactor the code if needed. Repeat.

Adopting TDD…


Putting Everything Together

In the seven previous parts of this series, I showed how to build, read and write a Huffman tree, the central data structure for Huffman compression.

Now we can put all those elements together to develop both a Huffman compressor and a decompressor.

Let’s define two skeletons:

A skeleton of…

Reading a Huffman Tree

In Part 6, I showed how to write a Huffman tree through a HuffmanTreeSerializer class.

We now want to perform the opposite operation: read a Huffman tree through a HuffmanTreeDeserializer class:

A skeleton of the HuffmanTreeDeserializer class.

Let’s write a test (by largely re-using/adapting the code written for Part 6):


Writing a Huffman Tree

In Part 5, I showed how to build a Huffman tree.

As explained in Part 1, implementing the Huffman compression and decompression algorithms requires being able to write and read a Huffman tree.

In order to write a Huffman tree, we want a HuffmanTreeSerializer class:

A skeleton of the HuffmanTreeSerializer…

Building The Huffman Tree

In Part 4, I briefly explained how a Huffman tree could be built and I presented a basic BinaryTree class to be used as a core data structure for our Huffman trees.

In this article, I will implement a Huffman tree builder.

The entire source code for this project can…


Building the Huffman Tree

As explained in parts 1, 2, and 3 of this series, the Huffman tree is the central data structure used for Huffman compression and decompression.

A Huffman tree is a binary tree, where each path from root to leaf represents a binary code: a 0 means a left-branch traversal, a…


In Parts 1&2, I described the idea behind Huffman data compression and decompression. Now it’s time to look at the basic tools to implement those algorithms.

The entire source code for this project can be found here: https://github.com/andrealaforgia/tdd-huffman-compression

The First Bit

It is by now clear that implementing Huffman compression will require handling…


In Part 1, I described the idea behind Huffman data compression.

Let’s look at the decompression algorithm.

The entire source code for this project can be found here: https://github.com/andrealaforgia/tdd-huffman-compression

We’re now using a variable number of bits to represent each character in the string to compress. In order to be…

Andrea Laforgia

Software Engineer at Oracle

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store