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

Huffman tree string representation

I need to make a String Representation of a Huffman Tree. It uses pre-order traversal and the output will produce a String using 'I' (for interior node) and 'L' (for leaf node) followed by the leaf node character. public static String…
2
votes
1 answer

Do we have to create a tree all the nodes of which have 3 children?

Steps to build Huffman Tree Input is array of unique characters along with their frequency of occurrences and output is Huffman Tree. Create a leaf node for each unique character and build a min heap of all leaf nodes (Min Heap is used as a…
Mary Star
  • 375
  • 7
  • 27
2
votes
2 answers

Bitstream of variable-length Huffman codes - How to write to file?

I'm working on a Huffman coding/decoding project in C and have a good understanding of how the algorithm should store information about the Huffman tree, re-build the tree during decoding, and decompress to the original input file using…
tiger2015
  • 31
  • 3
2
votes
1 answer

What tool lets me see gzip's Huffman table and blocks?

What tool lets me see the Huffman table that gzip and some other compression algorithms create? I know that programs like bzip2 and zpaq use additional compression techniques, but I believe gzip, zip, and the lz family of programs use Huffman…
user354134
2
votes
1 answer

How do I reverse a tuple in Haskell

I am having trouble figuring out how to reverse a tuple, below is my code: extractCode :: HTree -> HCodeMap extractCode t = extractCodeInner t [] where extractCodeInner (Leaf _ c) bits = [(c, [])] extractCodeInner (Branch _ left right)…
Howard
  • 53
  • 2
  • 9
2
votes
1 answer

Java-How to write bits and not characters in a file

I am trying to write a text compression program in java with huffman algorithm.I have already create the code for the encoding and i run my program from cmd like this: java Main inputFile outputFile where input is a txt file which contains 4 lines…
user4399798
2
votes
1 answer

Traversing helper method for a Huffman tree

In this programming assignment, we must make a helper method called traverse that is called by getCodes(). It is a recursive method to traverse the Huffman Tree and add a Code record to the ArrayList for each leaf node …
2
votes
2 answers

reading and writing bit to a file C++

I'm writing a program using Huffman algorithm to compress text file. I have tested my program by just printing the printing ASCII character to file and it worked fine. However, now I have to implement using bits and my program doesn't work. It seems…
Joe Cool
  • 209
  • 1
  • 3
  • 8
2
votes
2 answers

Why are these patterns in Huffman coding bitstreams in (Photoshop-produced?) JPG files?

This is a question, out of curiosity, about some patterns I see in JPG files when I look at them in a hex editor. I guess it is a question about the JPEG file format; why not this part is "random noise" like the rest, when it is supposed to be…
2
votes
2 answers

Huffman Decoding Algorithm

I am having trouble building my structure of the Huffman tree when decoding. Right now I am encoding the tree by if it has children making the prefix 0 and if it has no child make it 1. For example, a tree like (a,b,c,d) would be encoded as…
PictureMeAndYou
  • 533
  • 2
  • 5
  • 16
2
votes
1 answer

Compute the binary tree nodes count

Is it possible to compute how many nodes have arbitrary binary tree? The leaf count and the depth of every leaf are known (it is Huffman tree actually). I need it in order to be able to allocate needed memory for the tree before building it…
johnfound
  • 6,857
  • 4
  • 31
  • 60
2
votes
1 answer

Combining lossless data compression algorithms

I was wondering about how far we can take lossless data compression; I wasn't able to find an online simulator of lossless algorithms to perform some empiric testing. I could just make one on my own, but unluckily I don't have enough time in this…
2
votes
1 answer

Huffman trees triggering a breakpoint

I'm writing a program that given a root of a huffman tree, runs through the tree and gives me back an array of Symbols which represents the frequency of each letter in the tree. Symbol is defined like this: typedef struct { char chr; int…
shoham
  • 792
  • 2
  • 12
  • 30
2
votes
3 answers

Predict Huffman compression ratio without constructing the tree

I have a binary file and i know the number of occurrences of every symbol in it. I need to predict the length of compressed file IF i was to compress it using Huffman algorithm. I am only interested in the hypothetical output length and not in the…
2
votes
3 answers

After I build my Huffman tree the root's weight is 700k when I've read through 5megs of data

// Huffman Tree.cpp #include "stdafx.h" #include #include //Necessary to do any string comparisons #include #include #include //for exit() function using namespace std; class BinaryTree{ private: …
Azreal
  • 229
  • 3
  • 6
  • 16