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

Java - How to handle special characters when compressing bytes (Huffman encoding)?

I am writing a Huffman Compression/Decompression program. I have started writing my compression method and I am stuck. I am trying to read all bytes in the file and then put all of the bytes into a byte array. After putting all bytes into the byte…
Schytheron
  • 715
  • 8
  • 28
5
votes
1 answer

Huffman decoding (in Scala)

I'm trying to write an algorithm to perform Huffman decoding. I am doing it in Scala - it's an assignment for a Coursera course and I don't want to violate the honor code, so the below is pseudocode rather than Scala. The algorithm I have written…
adgeg
  • 53
  • 3
5
votes
2 answers

Canonical huffman encoding algo

Hello I am trying to implement Canonical huffman encoding but i dont understand wiki and google guides, I need explain more abstractly... I tried this: 1. Get list of regular huffman encoding length's codes. like this: A - code: 110, length: 3. B -…
user165210
  • 292
  • 4
  • 18
5
votes
3 answers

Priority Queues with Huffman tree

i am trying to create a Huffman tree by reading in a file and counting the frequency of each letter space symbol etc. i'm using a Priorityqueue to queue the items from smallest to largest but when i insert them into the queue they dont queue…
Zieklecknerizer
  • 275
  • 3
  • 6
  • 15
5
votes
2 answers

Huffman encoding with variable length symbols

I'm thinking of using a Huffman code to compress text, but with symbols of variable length (strings). For example (using an underscore as a space): huffman-code | symbol ------------------------------------ 00 | _ 01 | E 100 …
Laurent Grégoire
  • 4,006
  • 29
  • 52
5
votes
3 answers

Huffman code for a single character?

Lets say I have a massive string of just a single character say x. I need to use huffman encoding. A huffman encoding is a fully binary tree. So how does one create a huffman code for just a single character when we dont need two leaves at all ?
JavaDeveloper
  • 5,320
  • 16
  • 79
  • 132
5
votes
1 answer

Java: Storing bits in the most memory efficient manner

I have written an algorithm to implement Huffman Coding for compressing text files. It basically takes in a string as an input and generates a string of bits as output. However, I am having trouble storing this binary data as it is being stored as a…
Prathamesh
  • 51
  • 1
  • 2
5
votes
1 answer

Huffman Tree with Given Frequency Confuse as how to start? Java

I’m trying to understand what to do with my homework problem. I am trying to create a Huffman Tree that will encode and decode messages in Java. I am given Strings and Frequency. [a=10, b=15, c=12, e=3, nl=4, sp=13, t=1]. I know that with Huffman…
JavaStudent
  • 153
  • 1
  • 4
  • 13
5
votes
3 answers

How to Write a binary file in c++

I'm trying to implement the Huffman's encoding algorithm in c++. my question is : after i got the equivalent binary string for each character , how can i write those zeros and ones as binary on a file not as string 0 or string 1 ? thanks in advance…
HSN
  • 783
  • 3
  • 11
  • 20
4
votes
2 answers

Compressing strings with common parts

I have an application that manages a large number of strings. Strings are in a path-like format and have many common parts, but without a clear rule. They are not paths on the file-system but can be considered like so. I clearly need to optimize…
cprogrammer
  • 5,503
  • 3
  • 36
  • 56
4
votes
1 answer

Why octave error with function huffmandeco about large index types?

I've got a little MatLab script, which I try to understand. It doesn't do very much. It only reads a text from a file and encode and decode it with the Huffman-functions. But it throws an error while decoding: "error: out of memory or dimension too…
newOne
  • 43
  • 4
4
votes
1 answer

Octave - Huffman code doesn't work - All elements of SIG must be integers in the range [1,N]

I have a problem in Octave using huffmandict and huffmanenco. Here is my error : error: huffmanenco: all elements of SIG must be integers in the range [1,N] Here is my code : inputSig = [1 1 2 6 6 6 6 4 5 5]; list_symb = [1 2 6 4 5]; list_proba =…
4
votes
5 answers

How best to search binary data for variable length bit strings?

Can anyone tell me the best way to decode binary data with variable length bit strings in java? For example: The binary data is 10101000 11100010 01100001 01010111 01110001 01010110 I might need to find the first match of any of the following 01,…
joinJpegs
  • 1,287
  • 3
  • 14
  • 21
4
votes
2 answers

Huffman code tables

I didn't understand what do the Huffman tables of Jpeg contain, could someone explain this to me? Thanks
lital maatuk
  • 5,921
  • 20
  • 57
  • 79
4
votes
1 answer

Huffman coding in MATLAB - transmitting the dictionary/tree

I am working on compressing an arbitrary vector with MATLAB, which provides factory methods for Huffman Coding: huffmandict, huffmanenco, huffmandeco. The huffmandict function produces a lookup table mapping each symbol in the signal we want to…
Jay
  • 121
  • 1
  • 4