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
4 answers

I'm getting error C2664 on some I/O code

void BinaryTree::InitializeFromFile(string Filename){ ifstream inFile; inFile.open(Filename, fstream::binary); if(inFile.fail()){ cout<<"Error in opening file "<
Azreal
  • 229
  • 3
  • 6
  • 16
2
votes
1 answer

Compressing large dictionaries

I was trying to optimize memory usage of a particular service and stumbled upon a huge dictionary cache which gets queried for random entries very frequently. The problem is this dictionary takes up more than 1 GB and the service is almost touching…
v1p3r
  • 677
  • 7
  • 13
2
votes
3 answers

How to find the Compression ratio of a file using Huffman coding

I have compressed a binary file using Huffman encoding. Now i am trying to find the compression efficiency. In my Binary file i have symbols(bunch of 0 & 1) and frequency(repetition of symbols). suppose i have : symbol :0 freq : 173 symbol :1 freq :…
Sss
  • 1,519
  • 8
  • 37
  • 67
2
votes
3 answers

Smallest set of points that stabs an interval

Let X be a set of n intervals on the real line. We say that a set P of points stabs X if every interval in X contains at least one point in P. Describe and analyze an efficient algorithm to compute the smallest set of points that stabs X . Assume…
user3450427
  • 57
  • 2
  • 4
2
votes
2 answers

Freeing memory Binary trees

I have a function that creates a binary tree(*build_tree)* (Huffman). I also need a function that free's the memory that build tree allocated. It's my first time working with binary trees so I'm kind of confused. Should I create a loop that goes…
user3265963
  • 273
  • 3
  • 11
  • 18
2
votes
3 answers

How to decode huffman tree?

is there better way than just go left or right based on the input digit 0 or 1?
ohana
  • 51
  • 1
  • 3
2
votes
2 answers

How to delete any element at any particular position in array?

I have undergone a programming problem where i have to add the first two index of an array and then their sum must be at the first position (removing the two nodes which were added), surely that must result in shifting forward of rest of the array…
user3085082
  • 133
  • 4
  • 16
2
votes
2 answers

Extended Huffman code

I have this homework: finding the code words for the symbols in any given alphabet. It says I have to use binary Huffman on groups of three symbols. What does that mean exactly? Do i use regular Huffman on [alphabet]^3? If so, how do I then tell the…
user249555
  • 23
  • 3
2
votes
1 answer

Prove: Every absolute binary tree can represent a Huffman series

How can one prove that for every absolute binary tree (every node has either 0 or 2 children) there exists a Huffman series which can be represented by said tree. Any hints will be much appreciated!
AYR
  • 1,139
  • 3
  • 14
  • 24
2
votes
1 answer

How can I read the first two bytes of a .zip file to confirm that the appropriate magic number is present?

I'm trying to read in a .zip file that holds a compressed .txt file. How can I check for the magic number 0x00BC? Thanks. Edit: Sorry, should have specified that I'm trying to do this in java.
user2901181
  • 343
  • 4
  • 17
2
votes
2 answers

Mapping a list to a Huffman Tree whilst preserving relative order

I'm having an issue with a search algorithm over a Huffman tree: for a given probability distribution I need the Huffman tree to be identical regardless of permutations of the input data. Here is a picture of what's happening vs what I want:…
Tom Kealy
  • 2,537
  • 2
  • 27
  • 45
2
votes
2 answers

Huffman encoding in C

I am trying to write a module which assigns huffman encoded words to the input symbols, but the given codes differ from what they should look like. For example, if I run it with following symbol probabilities: (1st column: probabilities; 2nd column:…
Whizzil
  • 1,264
  • 6
  • 22
  • 39
2
votes
1 answer

Different results dependent on call of print

I decided to implement a small Huffman encoding script. After testing it on a small probablity list, I get the correct results when printing the tree during construction, and wrong results if I don't. What could be the cause of the problem? Here is…
Bartlomiej Lewandowski
  • 10,771
  • 14
  • 44
  • 75
2
votes
1 answer

Encoding intermediate leaves in the Huffman algorithm

I am encoding a set of items using Huffman codes, and, along with the final codes, I'd like to return the intermediate nodes encoded as well, but with the the data of the child nodes concatenated into the the data of the intermediate node. For…
Tom Kealy
  • 2,537
  • 2
  • 27
  • 45
2
votes
1 answer

Why does a label permutation produce a different Huffman code?

I'm generating Huffman codes based off the following input distributions: a = [(1,0.5),(0,0.25),(0,0.125),(0,0.125)] b = [(0,0.5),(1,0.25),(0,0.125),(0,0.125)] Where the only difference is the 1 is in a different bin. However when I encode these…
Tom Kealy
  • 2,537
  • 2
  • 27
  • 45