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

TypeError: '<' not supported between instances of 'HeapNode' and 'HeapNode'

When I try to push a node onto heap for the huffman tree I get this error: TypeError: '<' not supported between instances of 'HeapNode' and 'HeapNode' class HuffmanCoding: def __init__(self, path): self.path = path …
Austin
  • 49
  • 1
  • 6
4
votes
3 answers

Reconstructing Huffman tree from (preorder) bitstring in Haskell

I have the following Haskell polymorphic data type: data Tree a = Leaf Int a | Node Int (Tree a) (Tree a) The tree will be compressed in a bitstring of 0s and 1s. A '0' signifies a Node and it is followed by the encoding of the left subtree, then…
David
  • 447
  • 3
  • 15
4
votes
0 answers

Image compression with Huffman tree

So I recently built a Huffman tree and it worked well for encoding text. Now I wanted to try and see if I could compress images aswell. Obviously, images that differ little (like abstract images) should be better to compress. My question is if I'm…
apanTrazan
  • 41
  • 2
4
votes
2 answers

Can you draw a binary tree given its pre-order binary sequence/ordering?

Binary trees (and hence ordered forests) can be represented as binary strings. The binary string is obtained by traversing a binary tree in preorder, recording a 1 for every node and a 0 for every empty subtree (null link). This means that if I'm…
33ted
  • 689
  • 1
  • 5
  • 14
4
votes
1 answer

Deflate compression spec clarification(s)

my hope for this question (see: bottom) is to lay out as much as I know about the deflate process, and I can receive corrections on areas where I am (perhaps very) misinformed. Hopefully, at the end of it, this question could be a handy…
Trés DuBiel
  • 540
  • 3
  • 16
4
votes
2 answers

I don't understand this Huffman algorithm implementation

template void huffman(MinHeap*> heap, int n) { for(int i=0;i *first = heap.pop(); TreeNode *second = heap.pop(); TreeNode *bt = new…
user299648
  • 2,769
  • 6
  • 34
  • 43
4
votes
2 answers

Is there any way to parallelize Huffman encoding implementation on hardware?

The steps involved in Huffman encoding are quite sequential. So, I was wondering how could I introduce parallelism while implementing Huffman encoding on any platforms supporting parallel implementation, like GPUs, many core processor etc.?
4
votes
2 answers

Merge Order in Huffman Coding with same weight trees

I am really struggling with the order of merging trees that have the same "weight" in Huffman Coding. I looked into a lot of sources but all of them seem to cover just "simple cases" where there are no more than two elements with the same weight or…
Robert
  • 1,286
  • 1
  • 17
  • 37
4
votes
2 answers

Decoding Huffman file from canonical form

I am writing a Huffman file where I am storing the code lengths of the canonical codes in the header of the file. And during decoding, I am able to regenerate the canonical codes and store them into a std::map>. The…
WDRKKS
  • 125
  • 3
  • 11
4
votes
2 answers

writing bits into a c++ file

I'm working on Huffman coding and I have built the chars frequency table with a std::map frequencyTable; Then I have built the Huffman tree and then i have built the codes table in this way: std::map > codes; Now I…
Alfredo Liardo
  • 115
  • 2
  • 2
  • 10
4
votes
0 answers

Huffman decoding

Right now I am working on building the structure of the tree for the decoding part. It works when the input is small, but when it is large, the tree will not be built correctly. How I am encoding my inputs such as abc and it works up to…
user3281743
  • 295
  • 1
  • 11
4
votes
1 answer

Grayscale image compression using Huffman Coding in MATLAB

I am trying to compress a grayscale image using Huffman coding in MATLAB, and have tried the following code. I have used a grayscale image with size 512x512 in tif format. My problem is that the size of the compressed image (length of the…
parvathy
  • 47
  • 1
  • 1
  • 6
4
votes
3 answers

How could I do frequency analysis on a string without using a switch

I am working a school project to implement a Huffman code on text. The first part of course requires a frequency analysis on the text. Is there a better way aside from a giant switch and an array of counters to do it? ie: int[] counters for(int i…
Maynza
  • 748
  • 5
  • 18
4
votes
1 answer

Decoding a compressed short string; uncertain on compression used - Updated

I have a program that is compressing a string in an unknown way. I know a few inputs and the output produced, but I am not sure what is being used to compress the string. Here are my examples. (just 38 x a, no spaces or anything else) In: …
James
  • 139
  • 1
  • 9
4
votes
1 answer

PNG: deflate and zlib

I'm trying to understand compression in PNG - but I seem to find a lot of contradictory information online ... I would like to understand - how is searching done in the LZ77-part: hash table with linked lists? is this defined in deflate? or…
user3316835
  • 43
  • 1
  • 3