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
4
votes
2 answers

What is the running time and space complexity of a huffman decode algorithm?

Say we started with a text file like: a 00 b 01 c 10 d 11 00000001011011 The algorithm would be the typical one where you use the prefixes to build a Huffman tree, read in the encoded bits while traversing the tree until you reach a leaf, then…
atkayla
  • 8,143
  • 17
  • 72
  • 132
4
votes
2 answers

variations in huffman encoding codewords

I'm trying to solve some huffman coding problems, but I always get different values for the codewords (values not lengths). for example, if the codeword of character 'c' was 100, in my solution it is 101. Here is an example: Character Frequency …
a.u.r
  • 1,253
  • 2
  • 21
  • 32
4
votes
1 answer

Why permutate the code length codes ( Dynamic Huffman Codes | RFC-1951 )?

I've been studying RFC 1951 (the DEFLATE compression algorithm) and found the interesting "learning" source file by Mark Adler with a cute name -- puff.c. And while brain parsing that file has been an illuminating experience with reasonable…
4
votes
1 answer

Java loop and shifting

To cut a long story short, I'm trying to generate Huffman codes from a canonical Huffman list. Essentially, the following two loops should run, and generate a binary string. The code is: for (int i = 1; i <= 17; i++) { for (int j = 0; j <…
Tony
  • 3,587
  • 8
  • 44
  • 77
4
votes
2 answers

python huffman coding Exception Unorderable Types

i am trying to write the huffman coding in Python 3 with the code from http://en.literateprograms.org/Huffman_coding_%28Python%29 but it doesn't work. If i run the code in Python 2.7, it works well. The following lines are the…
4
votes
2 answers

Storing and reconstruction of Huffman tree

What is the best way to dehydrate a huffman tree, by dehydration I mean given a huffman tree, and the characters in each leaf, how can you efficiently store the structure of this tree, and later reconstruct it. take the below…
EasyQuestions
  • 327
  • 1
  • 10
  • 23
4
votes
1 answer

Why is my probability so far off with this Binary Tree using?

It's basically just an implementation of the Huffman Coding algorithm, but when I check the probability of the end BinaryTree (the only item in the queue left) it's grossly high. // Make a BinaryTree for each item in CharOccurrences and add as an…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
4
votes
3 answers

How can I print a bit instead of byte in a file?

I am using huffman algorithm to develop a file compressor and right now I am facing a problem which is: By using the algorithm to the word: stackoverflow, i get the following result: a,c,e,f,k,l,r,s,t,v,w = 1 time repeated o = 2 times…
4
votes
2 answers

Need help on BMP to JPEG conversion

I'm writing a C++ program to convert a BMP image into a JPEG. Here's the basic algorithm I'm trying to follow: Convert RGB color space to Y,Cb,Cr.. Down sample Cb and Cr by 2 (that means for each square block of 2*2 there is 4 different Y value but…
Umang
3
votes
1 answer

Jpeg huffman coding procedure

A Huffman table, in JPEG standard, is generated from a collection of statistics in two steps. One of the steps is implementing function/method given by this picture: (This picture is given in Annex K of JPEG standard): Problem is here. Previously…
MrD
  • 2,423
  • 3
  • 33
  • 57
3
votes
3 answers

How to generate Huffman codes from huffman tree

I'm making jpeg encoder in C++. I successfully create Huffman tree, but how do I generate huffman codes from tree? One way I tried was to assign 0 to left branch and 1 to right branch, just like in the picture, but there is a problem in this…
MrD
  • 2,423
  • 3
  • 33
  • 57
3
votes
9 answers

Huffman compression algorithm

I've implemented file compression using huffman's algorithm, but the problem I have is that to enable decompression of the compressed file, the coding tree used, or the codes itself should be written to the file too. The question is: how do i do…
agnieszka
  • 14,897
  • 30
  • 95
  • 113
3
votes
1 answer

Matlab, Image compression

i am unsure about what this is asking me to do in matlab? what does it mean to encode? what format should the answer be? can anyone help me to work it out please? Encode the 8x8 image patch and print out the results I have got an 8X8 image…
meena
  • 31
  • 1
  • 2
3
votes
1 answer

How to compress an alphabet consisting of DNA sequence

I want to compress a DNA sequence with a compression technique rather than Huffman and Adaptive Huffman algorithm, i'm using c# as a programming language. can anyone lead me to an algorithm. Note: I want a lossless compression
Sara S.
  • 1,365
  • 1
  • 15
  • 33
3
votes
2 answers

Huffman encoding - header & EOF

I am currently working on implementing a program based on the huffman algorithm in Java, and I am at the stage where I need to output the encoded content to a file. I am a bit confused about how to implement the header and eof needed for decoding.…
LDM91
  • 437
  • 1
  • 7
  • 16