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

Huffman trees for non-binary alphabets?

Is there an easy generalization of Huffman coding trees for situations where the resulting alphabet is not binary? For instance, if I wanted to compress some text by writing it out in ternary, I could still build up a prefix-free coding system for…
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
6
votes
1 answer

How to write Huffman coding to a file using Python?

I created a Python script to compress text by using the Huffman algorithm. Say I have the following string: string = 'The quick brown fox jumps over the lazy dog' Running my algorithm returns the following 'bits': result =…
Pim Klaassen
  • 95
  • 1
  • 7
6
votes
3 answers

Outputting bit data to binary file C++

I am writing a compression program, and need to write bit data to a binary file using c++. If anyone could advise on the write statement, or a website with advice, I would be very grateful. Apologies if this is a simple or confusing question, I am…
Drew C
  • 91
  • 1
  • 6
6
votes
4 answers

Structure for an array of bits in C

It has come to my attention that there is no builtin structure for a single bit in C. There is (unsigned) char and int, which are 8 bits (one byte), and long which is 64+ bits, and so on (uint64_t, bool...) I came across this while coding up a…
Cary Shindell
  • 1,336
  • 8
  • 25
6
votes
2 answers

Infinite Recursion, StackOverError in huffman tree

I am working on a Huffman Encoding program and I am almost finished but I am stuck in an infinite recursion loop. Does anyone have an idea where this is going wrong? This is the error I am getting: Exception in thread "main"…
user1093111
  • 1,091
  • 5
  • 21
  • 47
6
votes
1 answer

PHP Efficient way to Convert String of Binary into Binary

here is the skinny (scroll down to see the problem): I am doing Huffman Encoding to compress a file using PHP (for a project). I have made the map, and made everything into a string like so: 00101010001100001110011101001101111011111011 Now, I need…
Addo Solutions
  • 1,619
  • 3
  • 20
  • 37
6
votes
3 answers

Huffman encoding

Under what conditions does Huffman encoding make a string not compressible? Is it when all the characters appear with equal frequency/probability? And if so, how can one show this is true?
DillPixel
  • 955
  • 1
  • 14
  • 20
6
votes
2 answers

Why does this code work for this TopCoder prob?

I've been trying to think since HOURS about this TopCoder problem and couldn't come with a perfectly working solution and found the one given below that is insanely beautifully used! I'm trying to figure how this solution works for the given probem?…
GrowinMan
  • 4,891
  • 12
  • 41
  • 58
5
votes
3 answers

Measuring efficiency of Huffman coding with Python bitstring

I have the following string that I would like to Huffman-encode and store efficiently into a bit array: >>> print sequence GTCAGGACAAGAAAGACAANTCCAATTNACATTATG| The frequencies of the symbols in sequence are: >>> print…
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
5
votes
2 answers

How to create Huffman tree from FFC4 (DHT) header in jpeg file?

I thought I could work this one out myself but I don't seem to be moving forward at all. Ok, the background: I need to create a Huffman tree of codes from the information provided by the FFC4, DHT (Define Huffman Table) header in a jpg file. The DHT…
joinJpegs
  • 1,287
  • 3
  • 14
  • 21
5
votes
3 answers

Optimal way to compress 60 bit string

Given 15 random hexadecimal numbers (60 bits) where there is always at least 1 duplicate in every 20 bit run (5 hexdecimals). What is the optimal way to compress the bytes? Here are some examples: 01230 45647 789AA D8D9F 8AAAF 21052 20D22 8CC56…
ParoX
  • 5,685
  • 23
  • 81
  • 152
5
votes
3 answers

Estimating max payload size on a compressed list of integers

I have 1 million rows in an application. It makes a request to a server such as the following: /search?q=hello And the search returns a sorted list of integers, representing the rows that have been matched in the input dataset (which the user has…
David542
  • 104,438
  • 178
  • 489
  • 842
5
votes
1 answer

How to convert a byte array to string?

I just finished creating a huffman compression algorithm . I converted my compressed text from a string to a byte array with bytearray(). Im attempting to decompress my huffman algorithm. My only concern though is that i cannot convert my byte array…
5
votes
3 answers

How to rebuild the dynamic Huffman tree from DEFLATE

This question is in regards to section 3.2.7 of RFC-1951, rebuilding the dynamic Huffman tree. Each code is defined by a sequence of code lengths, such that all codes of a given bit length have lexicographically consecutive values. For example,…
Dave P
  • 145
  • 8
5
votes
2 answers

PHP Huffman Decode Algorithm

I applied for a job recently and got sent a hackerrank exam with a couple of questions.One of them was a huffman decoding algorithm. There is a similar problem available here which explains the formatting alot better then I can. The actual task was…
Kieran
  • 51
  • 2
1 2
3
70 71