-4

How would you iteratively build a huffman code? All solutions I have seen are recursive. I was curious if an iterative solution was possible.

1 Answers1

0

The Huffman algorithm is not recursive to begin with, and I've never seen a recursive implementation.

You might be talking about traversing the Huffman tree once the algorithm has built it. That can be recursive, but a traversal, as well as the tree itself, is not necessary. All you need for each symbol is how many bits are in the code for that symbol. With that you can sequentially generate a canonical code, i.e. assignment of actual bit values, to each symbol. The number of bits can be a direct result of the Huffman algorithm implementation, as in Moffat's implementation.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158