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

Huffman encoding: The constructor HuffmanCoding(Map>, List) is undefinedJava(134217858)

this is the code from Huffman.java public static HuffmanCoding encode(String input) { char ch; Map> inputData = buildCode(treeFromFreqTable(freqTable(input))); List mylist = new…
-1
votes
1 answer

Huffman Coding and Huffman Tree

I am learning Huffman coding and trying to find the following answers: Can Huffman tree ever be a list? If yes, then in which case? If no, then why? In Huffman coding, is it possible to have exactly two symbols with the longest codeword length? If…
-1
votes
1 answer

incorrect binary tree

while(count != 25) { tail = head; new_node = (binary_node*)malloc(sizeof(binary_node)); while(tail->next != NULL) tail = tail->next; tail->next = new_node; new_node->element.frequency = (p->element.frequency +…
shinshin32
  • 139
  • 2
  • 2
  • 6
-1
votes
1 answer

How to calculate length of each Huffman code?

The output for the code looks like this how can I calculate the length of the code lets say here I got Huffman lengths 1,10,11 now how can I calculate the length of each code so that I get {1,2,2}. I tried to print some things but it was printing…
User1086
  • 11
  • 2
-1
votes
2 answers

How to save a Huffman table in a file In a way that use the least storage?

It's my first question in stack overflow. it's long but I have explained it in detail and I think it's understandable. I'm writing huffman code by c++ and saved characters and codes in a table like this: Text:…
mohammad
  • 3
  • 3
-1
votes
1 answer

java Hufman: Encoding of the Huffman

I'm trying to code a Huffman as a bit of homework, and I'm a bit confused about how I should start creating the Huffman tree. I am aware that the Huffman tree takes the two lowest frequencies and makes them into a tree with the sum of their…
Oliver
  • 29
  • 3
-1
votes
3 answers

How to Use Huffman code for compress file?

My program stores Huffman code in a char[8] variable. I want to store it in an unsigned char variable. I do it, but don't think it works correctly because when I used the following code to extract my file it didn't work: unsigned char bit2byte (…
zahratTZ
  • 21
  • 1
  • 4
-1
votes
1 answer

I cant assign an array to a array inside of my structure

I was doing my Huffman homework and I got stumble on a tiny thing that I cant understand why it happens. So I created a structure that has an int array a char and an int that holds the size of the array. struct kodlar{ char karakter; int*…
T.K
  • 41
  • 7
-1
votes
1 answer

How to output a list of binary-looking, huffman-encoded values to a "bin" file?

I am working on this Huffman Encoding project. But I am stuck on how to use this code table to output the Huffman codes into "bin" file using java? The list in the red box is "String" of a list of differently long, comma-separated groups of zeros…
Ray
  • 103
  • 1
  • 8
-1
votes
1 answer

Can I have Huffman encoding without fixed or variable table

There's a need where one cannot transfer Huffman coding table with other. Is there a possibility of not having Huffman table but still decode the message at recipient side?
NIGHT077
  • 11
  • 6
-1
votes
1 answer

why huffman code algorithm with 2 queues and sorted input cna be O(n)

I read this algorithm for using 2 queues to implement Huffman codes, and it claims that with sorted input the runtime can be O(n): https://www.geeksforgeeks.org/efficient-huffman-coding-for-sorted-input-greedy-algo-4/ I do not quite understand why…
-1
votes
1 answer

How do i store binary 1s and 0s as bits rather than bytes in a file in python3?

I'm trying to do file compression using huffman encoding in python and i have successfully constructed the codes for each of the unique characters in the file. Now, when i encode the original file with this code it generates a sequence of 1s and 0s.…
-1
votes
1 answer

How to write byte(s) to a file in C++?

I have created a bitset using std::bitset<8> bits which is equivalent to 00000000 i.e., 1 byte. I have output file defined as std::ofstream outfile("./compressed", std::ofstream::out | std::ofstream::binary) but when I write the bits using outfile…
Abhinav
  • 429
  • 5
  • 13
-1
votes
1 answer

Huffman encode single character without lookup table

I am trying to implement Huffman Coding and can't figure out how to encode a character using the trie without generating a lookup table. What I don't want to do is generate a map of each character to its encoded string of bits. I am trying to write…
user11036426
-1
votes
1 answer

huffman coding using stl and without nodes c++

the code has to print the huffman code for the characters in the string but it is giving wrong code for some characters (mostly for the chacters that get code 1 at the end #include #include #include #include using…
Eswar Saladi
  • 117
  • 8