2

I know that adaptive huffman has better performance than huffman algorhitm, but I can't figure out why.

In Huffman, when you build a tree and encode your text, you must send frequencies for each letter in text with encoded text. So when decoding, you build a tree, like you did when you were encoding, and then decode the message.

But in adaptive huffman, when you build a tree and encode text, I guess you must send message with built huffman tree? I may be wrong, but it seems that it's easier to send table containing letter frequencies, than whole tree.

Where am I wrong?

user2090925
  • 65
  • 3
  • 10
  • You don't have to send frequencies, you can send lengths. – harold May 06 '15 at 16:14
  • Yes, that what I meant... but adaptive huffman is supposed to be better.. so why is it better to send whole tree, than send just lengths? – user2090925 May 06 '15 at 16:17
  • If a file (or block) has different letter frequencies in different regions, then adaptive huffman can use shorter codes for frequent letters in each of those regions, whereas static huffman can only use the average for the whole file. If the file is so short that you can't get any benefit from that then you instead benefit from not having to attach any header (whether it be tree or frequency data). – sh1 May 06 '15 at 17:01
  • @sh1 But then, when decoding, you must have multiple trees, for different regions in file? – user2090925 May 06 '15 at 17:09
  • Most lengths will be very similar and can be compressed in a way that exploits this. Frequencies of similar-length codes, however, can still vary significantly and carry a lot of information you don't want. – sh1 May 06 '15 at 17:15
  • [Adaptive huffman](http://en.wikipedia.org/wiki/Adaptive_Huffman_coding) doesn't need to transmit any header at all. The tree is based on what's already been transmitted. Obviously it becomes inefficient when there's a sharp change of letter distribution, but then it adapts. – sh1 May 06 '15 at 17:17
  • @sh1 but if I transmit somtehing like 0110001 how can you build tree from that? In huffman you would build a tree from header, and then find out which code is for which letter.. but I can't seem to understand, how you do that in adaptive huffman.. – user2090925 May 06 '15 at 17:24
  • Adaptive huffman builds a tree from the letter frequencies of what has already been transmitted. You start with all-zeroes and assume a flat tree (both sender and receiver start with the same preconditions so they can communicate meaningfully) and according to an agreed protocol, both sender and receiver re-balance their trees in the same way based only what they both already know. – sh1 May 06 '15 at 17:32
  • So with adaptive huffman, you dont really compress whole file and then send it? – user2090925 May 06 '15 at 17:34
  • Adaptive is all done in a single pass. No readahead is required and the latency is just a single character. It works on knowledge of the past. Static huffman works with knowledge of the future, and as a consequence it has to share that knowledge with the decoder before decoding can start. Because adaptive pays no transmission penalty for doing so, it can re-optimise the tree for every single character. Static would pay huge overheads for such rapid change. I think Deflate uses static chunks (multiple trees) to get some adaptive benefit using static trees. – sh1 May 06 '15 at 17:49

1 Answers1

2

No, you don't send the code. An adaptive Huffman code is adjusted incrementally using the data already received. That process is replicated on the receiving end.

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