Questions tagged [huffman-code]

Huffman coding is a lossless compression algorithm that is optimal, assuming all input characters are drawn from a known discrete distribution.

Huffman coding is an algorithm that builds a variable-length, prefix-free code for each character in an alphabet based on the frequency of that character. The algorithm works by greedily assembling an encoding tree by combining together encoding trees for individual characters based on their weights. Low-weight trees are combined together until only a single tree remains.

Useful links

1053 questions
2
votes
2 answers

Non exhaustive pattern error when decoding Huffman tree?

I'm trying to turn a Huffman tree and a stream of bits into a list of characters plus a boolean indicating whether or not the output consumed all the input bits. Here's an example: decode xyz_code [True,False,True,True,True,False,False,True] =…
2
votes
1 answer

huffman algorithm in python

HI! Could anybody say how to fix the problem in the Huffman algorthm (if put together all the parts) from this Internet site: http://www.builderau.com.au/program/python/soa/Huffman-coding-in-Python/0,2000064084,339283616,00.htm Error: itemqueue = …
user721588
2
votes
1 answer

in zlib what happen when the Huffman code lengths for the alphabets exceed maximum code length(15)?

in https://www.rfc-editor.org/rfc/rfc1951 Note that in the "deflate" format, the Huffman codes for the various alphabets must not exceed certain maximum code lengths. the max code length definition is 15. what happens when the Huffman code…
tim
  • 23
  • 2
2
votes
1 answer

Should we Include spaces in Huffman Coding method

When we encode using huffman coding method.Should we include spaces into consideration as well?
Sahan Randika
  • 47
  • 1
  • 14
2
votes
1 answer

Steps to compress a file using Huffman Code

I know there are many questions involving Huffman Code, including another one from myself, but I am wondering what would be the best way to actually encode a text file. Decompression seems trivial; traversing the tree, going left at 0 and right on…
Trevor Arjeski
  • 2,108
  • 1
  • 24
  • 40
2
votes
1 answer

Comparator and Priority Queues

I'm in the process of coding Huffman Code where I import a file, generate huffman code for each character, then output the binary to a file. To import the characters I am using a scanner that reads each character, puts it in a node that has values…
Trevor Arjeski
  • 2,108
  • 1
  • 24
  • 40
2
votes
1 answer

When using Huffman encoding for binary data, how are characters determined?

All the examples of Huffman encoding I've seen use letters (A, B, C) as the character being encoded, in which they calculate the frequencies of each to generate the Huffman tree. What happens when the data you want to encode is binary? I've seen…
Steven Yang
  • 358
  • 3
  • 11
2
votes
2 answers

For Ternary Huffman problem, can we make a tree (or encoding scheme) for "4" characters?

For Ternary Huffman problem, can we make a tree (or encoding scheme) for "4" characters?" Say I have 4 characters with these frequencies: freq(a)=5 freq(b)=3 freq(c)=2 freq(d)=2 How will I encode them in the form of 0,1,2 such that no code word is a…
2
votes
2 answers

The most efficient way to deal with bits for compression in JavaScript

I have never done compression but am interested in the Huffman encoding. They show this as a simple demo encoding for the first few letters: A 0 E 10 P 110 space 1110 D 11110 T 111110 L 111111 The standard Huffman encoding…
Lance
  • 75,200
  • 93
  • 289
  • 503
2
votes
0 answers

Is it possible to encode and decode jpeg by blocks?

I want to develop some very specific UDP protocol, with following workflow: It is very simple in design, and very "realtim'ish", in contrast to stubs like HTTP MJPEG streaming technique: it could fully utulize even narrow channel to deliever as…
xakepp35
  • 2,878
  • 7
  • 26
  • 54
2
votes
1 answer

Huffman Coding Using Doubly Linked List

I am developing an implementation of Huffman Compression in x64 MASM. My main function in C syntax would be: void* huffCompress(void* lpDataStream, unsigned long long qwLength); I am using Microsoft's Fastcall convention where the paramters are…
Display name
  • 187
  • 8
2
votes
1 answer

How to traverse tree for making binary code from a HuffmanTree?

I'm trying to make binary code from a Huffman tree. I am stuck at tree traversal. To traverse tree and print code for every character frequency, I've written following code. def printCode(node,prefix=""): if node.left: prefix =…
exiled
  • 305
  • 2
  • 11
2
votes
2 answers

C# - Huffman coding for a large file takes too long

I am trying to implement Huffman coding in C#. I have a problem with encoding large files as it takes too much time. For example to encode a 11MiB binary file it takes 10 seconds in debug mode. And I did not even bother waiting for my program to…
Popa611
  • 121
  • 2
  • 10
2
votes
1 answer

Understanding IDAT, reading DEFLATE's dynamic Huffman tree

I am looking to better understand zlib, deflate, and PNG encoding. With that said, I am having trouble applying the specifications of RFC-1950 and RFC-1951 to the IDAT portion of a PNG. Below is binary for an image. The example image is 50x50 and…
Dave P
  • 145
  • 8
2
votes
1 answer

Decoding a Huffman Tree from a File

I'm trying to decode a Huffman code. I got a dictionary of chars, with an int value and a binary value of it and the binary values of the words, and it looks like…
Esteban
  • 55
  • 6