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

Trying to make a Huffman tree in C, but it keeps saying heap-buffer-overflow

#include #include #include #include #include #include "huffman.h" // Structures defined here. struct hmNode { struct hmNode *left; char ch; freq f; bool used; struct hmNode…
-1
votes
1 answer

Using a huffman tree to decode binary text

The snippet below is not returning the correct text. The code takes in a pointer to the root node of a Huffman code tree and a binary text, which it then converts. However, every time it returns a single letter repeated. string decode(Node *root,…
-1
votes
2 answers

Convert list comprehension to for loop

On this Huffman code, I found the below code. heap = [[wt, [sym, ""]] for sym, wt in symb2freq.items()] Is that possible to convert this kind of list compression into a for-loop?
Matthew
  • 17
  • 6
-1
votes
1 answer

huffman encoding using c

so I have hit a block with my code and i just cant seem to understand why I am segfaulting at the very end when i try to print out a string of encoded binary digits for a huffman tree. I have used gdb to double check my work and i just cant seem to…
Mihai G
  • 27
  • 2
  • 5
-1
votes
1 answer

How to traverse through a huffman tree and access stored characters?

I am trying to make a simple program which will accept a string input, generate nodes for every character, generate a huffman tree from these nodes, create a hashmap mapping the characters to their encoded bits, and print the input using the hashmap…
-1
votes
1 answer

Size of weights extracted from a NN model becomes higher than the model

I tried extracting the weights from a .pb tensorflow model and stored them in a text file..the size of the text file itself is higher than the model..why is this happening..? Thanks in advance Code to extract weights : import tensorflow as tf from…
theavatar
  • 115
  • 1
  • 9
-1
votes
1 answer

Reading the Huffman encoding tree in C#

I'm trying to build a Huffman encoder that can read the bytes out of a text file and convert them to Huffman codes. And I need to be able to decode. So far I've been able to read the bytes from a file and put them in an tree that is based on a…
B. Dionys
  • 916
  • 7
  • 34
-1
votes
1 answer

Reverse Huffman's algorithm?

I have a problem simlar to Huffman's encoding, I'm not sure exactly how it can be solved or if it is a reverse Huffman's encoding. But it definitely can be solved using a greedy approach. Consider a set of length, each associated with a…
bli00
  • 2,215
  • 2
  • 19
  • 46
-1
votes
1 answer

Huffman Coding Creating Tree C++

The code is a part of bigger solution. When I have only one element in prioriQueue, lastLeft and lastRight are nullptr. Any idea how to change this algorithm to work corectly with only one element, or some tips how to write it better? Problem is in…
-1
votes
1 answer

Solving Huffman Code Tree

I was expecting a little help in my discrete maths problem. Is there any way to shorten up the binary tree or I have to construct for the whole data below. Construct a Huffman code for the letters of the English alphabet where the frequencies of…
-1
votes
2 answers

Sending raw binary data over sockets in Python 3

I'm working on Huffman Encoding and Decoding. I have encoded a string into binary using Huffman Algorithm and now i want to send it over to another computer over sockets using Python 3 where the encoded data will be decoded back. What would be the…
the_blank
  • 9
  • 1
  • 5
-1
votes
2 answers

longest huffman codeword

I'm not quite sure how to determine what the longest possible codeword is under Huffman encoding for a specific set of frequencies? Any ideas?
-1
votes
1 answer

Unable to access root from Tree

I have created a huffman tree, and I now need to traverse the huffman tree to decode a message. I am writing the method to traverse the huffman tree, and I am unable to access the current node of my tree, even though I passed it my tree. Any help…
-1
votes
1 answer

How can I write binary bits into binary file in C?

I am trying to implement Huffman encoding in C. I am done with the tree construction and obtained the codeword for each symbol as the algorithm proceeds. But now I am stuck with insertion of the codewords into binary files for the corresponding…
Anib
  • 31
  • 1
  • 3
-1
votes
1 answer

Huffman tree stuck at last non-internal node

So I've made a function to build a huffman tree which is passed a linked list in ascending order of frequencies (a value assigned within each node) but it seems to get stuck when its down to the last 'non internal node', as in a node in the linked…
Finlandia_C
  • 385
  • 6
  • 19