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
3
votes
1 answer

Huffman encoding: how to write binary data in Python

I have tried methods using the struct module, as shown by the lines commented out in my code, but it didn't work out. Basically I have two options: I can either write the binary data code by code (my code are sequences of bits of length varying from…
ratsimihah
  • 1,010
  • 1
  • 11
  • 22
3
votes
1 answer

TypeError: on heapq.heapop on python3 but but working in python2

I am working on a genome compression algorithm using variations of Huffman coding. I have the following piece of code in python2: def makeHuffTree(trees): heapq.heapify(trees) while len(trees) > 1: childR, childL = heapq.heappop(trees),…
3
votes
1 answer

What happens if we are inconsistent while creating Huffman Tree?

Why can’t we be inconsistent while creating Huffman Tree i.e sometime make the higher frequency node left child and sometimes right I know per convention, we have to decided beforehand if we would assign the larger node to the left or right child…
Surbhi Jain
  • 369
  • 1
  • 11
3
votes
2 answers

package-merge algorithm for length-limited huffman codes

The explanation below is from Wikipedia about length-limited Huffman codes using package-merge. I can not understand, I have some questions about this. how we package? how we merge? how we recognize the length of bit string for symbols? Let L be…
user693711
  • 77
  • 2
  • 5
3
votes
3 answers

Build a huffman tree in scheme

I'm suffering with this problem for a few days now. How can you build a tree with the data as specified on the following site: http://www.impulseadventure.com/photo/jpeg-huffman-coding.html, under the topic: The actual DHT in the JPEG file I'll…
Jeremy Knees
  • 652
  • 1
  • 7
  • 21
3
votes
2 answers

How to create a binary tree from a frequency dictionary

I'm fairly new to coding and I'm having difficulty creating a huffman algorithm to encode and decode text files. I understand most of the concepts pretty well but there's not much on exactly how you would create and traverse the tree. Here's my code…
user11167665
3
votes
1 answer

What is the most efficient(*) way of building a canonical huffman tree?

Assume A is an array where A[0] holds the frequency of 0-th letter of the alphabet. What is the most efficient(*) way of calculating code lengths? Not sure, but I guess efficiency can be in terms of memory usage or steps required. All I'm interested…
Igor Gatis
  • 4,648
  • 10
  • 43
  • 66
3
votes
2 answers

How to force haskell to don't store whole bytestring?

I writing a small (relatively) application on haskell in academic purpose. I'm implementing a Huffman compression, based on this code http://www.haskell.org/haskellwiki/Toy_compression_implementations . My variant of this code is here…
kravitz
  • 973
  • 2
  • 10
  • 22
3
votes
2 answers

How can i generate a binary code table of a huffman tree?

I want to implement an function which gives me a binary code for each char in a huffman tree. To implement the function i tried traversing the table by using a recursive function. However i don't know how to fill the result the binary code for each…
Bart
  • 43
  • 1
  • 11
3
votes
1 answer

Huffman Code writing bits to a file for compression

I was asked to use huffman code to compress an input file and write it to an output file. I have finished implementing the huffman tree structure and generating the huffman codes. But I dont know how to write those codes into a file so that the file…
adonayresom
  • 280
  • 3
  • 15
3
votes
1 answer

Java - Is Tree an instance of Node?

I was browsing the web in the hope of finding something that will help me build a HuffmanTree and I stumbled across this code from http://rosettacode.org/wiki/Huffman_coding#Java. I am new to Java and wasn't able to use this as it is way above my…
Schytheron
  • 715
  • 8
  • 28
3
votes
1 answer

Is there an open-source implementation of the Dictionary Huffman compression algorithm?

I'm working on a library to work with Mobipocket-format ebook files, and I have LZ77-style PalmDoc decompression and compression working. However, PalmDoc compression is only one of the two currently-used types of text compression being used on…
clee
  • 10,943
  • 6
  • 36
  • 28
3
votes
3 answers

How to constantly find the two smallest values from two different lists?

I have two different lists that contain integers and I need to constantly find the two smallest values between these two lists; I should note that I do NOT want to merge these two lists together, since they are different types. I would like to know…
bob dylan
  • 647
  • 1
  • 10
  • 25
3
votes
4 answers

need help on how to encode words using huffman code

how do you encode words using the huffman code such as NEED
denise
3
votes
2 answers

Convention for Huffman Coding

Is there a convention for generating a Huffman encoding for a certain alphabet? It seems like the resultant encoding depends both on whether you assign '0' to the left child or the right child as well as how you determine which symbol will go to the…
andars
  • 1,384
  • 7
  • 12