2

When we encode using huffman coding method.Should we include spaces into consideration as well?

Sahan Randika
  • 47
  • 1
  • 14
  • 2
    Spaces are just characters, so these are encoded exactly the same way (just like all other characters, like `~`, `@`, `!`, etc.) – Willem Van Onsem Jul 07 '19 at 17:25
  • 1
    Why would you omit any character? That only adds complication. And makes it impossible to decompress to 100% the same text. – H H Jul 07 '19 at 17:43
  • 2
    Ifyouleaveoutthespacesitwillbehardtoreadthedecompressedtext. – rici Jul 07 '19 at 18:09

1 Answers1

5

The Huffman coding [wiki] encodes a stream of characters. These characters can include spaces, symbols, emoji characters, characters with diacritics, etc.

So we take spaces into account as well, otherwise if we would decode the string, the decoded string will not contain these spaces anymore.

In fact the Wikipedia article contains an image of a Huffman encoding tree that shows a space, at the righmost leaf:

Huffman encoding image on Wikipedia

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555