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

Let X,Y,Z,W be words with vector frequency $(x,y,z,w)$ , Find an optimal code

Let X,Y,Z,W be words with vector frequency (x,y,z,w) such that . Find certain requirements about x,y,z,w such that W=00,Z=01,Y=10,X=11 is an optimal code. My solution : Using Huffman coding, I think the solution is to demand The tree is : In a…
Algo
  • 185
  • 6
2
votes
0 answers

find minimal integral generators for a Huffman tree

A (memoryless) source generates symbols a1, a2, ... an with relative frequencies f1, f2, ... ,fn. Assume that the frequencies are all positive. An optimal prefix-free code for this source can be determined using most variants of the Huffman…
sitiposit
  • 149
  • 1
  • 13
2
votes
3 answers

Is there a way in Java to read new line characters in a text file?

I'm implementing a huffman coding program. I encode and decode an entire book, so finding new line characters is very important, and something I overlooked, unfortunately. Currently, I use a method to read the small book into a String that is then…
WeekendJedi
  • 67
  • 10
2
votes
7 answers

Are algorithms like Huffman coding actually used in production?

Currently, I am developing an app that needs to store large amount of text on an iPad. My question is, are algorithms like Huffman coding actually used in production? I just need a very simple compression algorithm (there's not going to be a huge…
Nick Anderegg
  • 1,006
  • 1
  • 12
  • 25
2
votes
1 answer

CPP:How to get the REAL element in a vector?

I'm new of C++ and I'm making a huffman tree written in c++, and I'm in trouble in generating tree structure. Here is my code: void Huffman::generateTree() { std::vector nodes; for (auto itr : freq) { …
user16161541
2
votes
1 answer

JT file format : Building huffman tree

I am trying to read a JT File. JT file may have information which is compressed by using Huffman Algorithm. I am facing a problem while building the Huffman tree. There's an ambiguity in the implementation which occurs when two symbols have the same…
Isentropic
  • 145
  • 2
  • 7
2
votes
3 answers

problem in saving Huffman Code?

I want to save Huffman codes into a file. How can I do this? I am saving Huffman codes into a string but size of generated file is bigger than Original file.
zahratTZ
  • 21
  • 1
  • 4
2
votes
1 answer

How to find weights given a Huffman tree

Huffman's algorithm derives a tree given the weights of the symbols. I want the reverse: given a tree, figure out a set of symbol weights that would generate that tree a tree with the same bit lengths for each symbol. I'm aware that there are…
Pedro Gimeno
  • 2,837
  • 1
  • 25
  • 33
2
votes
1 answer

Where does my Huffman encoding method go wrong?

I am trying to code a Huffman string encoding algorithm. My solution works this way: since every letter in the string have a special binary code associated to it, search the binary tree and when a letter is found, add it to the map with binary…
2
votes
1 answer

Encoding Huffman Tree Scheme

I am trying to write a function, (codeWords t), which traverses a Huffman tree (adds #\0 when it goes left, adds #\1 when it goes right...) and returns these values in pairs of the symbol at a leaf along with its associated encoding as a string over…
2
votes
1 answer

How to traverse a Huffman tree?

I'm new to programming and I'm currently trying to learn Python. I'm doing am following a tutorial that consist in building a Huffman coding app through 4 steps; I've got the first 3 but I'm stuck in the fourth. First step is getting the frequency…
DVM
  • 23
  • 4
2
votes
1 answer

How to store tree during recursion? (Huffman decoding)

I'm trying to learn Haskell. I am trying to implement a Huffman Tree. The parameters of my decode function are (basically, the 'signature'): decode :: HTree -> [Int] -> [Char] So, given the tree, and a list of numbers, I want to return the decoded…
2
votes
0 answers

Static vs Dynamic Huffman Encoding

I was just wondering if you choose to implement both Static and Dynamic Huffman in your Deflate Algorithms (Zlib), how would you choose which one to implement in a specific data block. In my understanding, you have to do 2 passes to the compressed…
ripa
  • 33
  • 1
  • 3
2
votes
0 answers

Priority Queue not adding data correctly in the tree

I'm trying to implement Huffman's Coding algorithm in python but when I try to add node data in the tree I'm not getting the correct output values? Here is the code that I have so far for adding the nodes: n = 6 charArray =…
Richard Desouza
  • 249
  • 4
  • 13
2
votes
0 answers

Why are children nodes are 2*i+1 and 2*i+2?

I'm currently trying to implement Huffman's compression algorithm using a Priority Queue (Min Heap). I've found a resource online that could help me, although there is a piece of code I do not understand, and unfortunately I do not find any…
Nikola Stoilov
  • 85
  • 1
  • 10