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

Finding the length of compressed text (Huffman coding)

Given a text of n characters and a Binary tree, generated by Huffman coding, such that the leaf nodes have attributes: a string (the character itself) and an integer (its frequency in the text). The path from the root to any leaf represents its…
zerrus011
  • 61
  • 5
2
votes
3 answers

Is this the correct way of writing bits to big endian?

Currently, it's for a Huffman compression algorithm that assigns binary codes to characters used in a text file. Fewer bits for more frequent- and more bits for less-frequent characters. Currently, I'm trying to save the binary code big-endian in a…
Ji Kang
  • 31
  • 4
2
votes
2 answers

Huffman Coding for Markov Chain based on conditional distribution

Before I start describing my problem, I would like to note that this question is for a project for one of my courses at University, so I do not seek for the solution, rather for a hint or an explanation. So, lets assume that there are 3 states…
2
votes
1 answer

List all leaves of Huffman tree

This is my Huffman coding that returns an empty list. My purpose was to make it add all the pairs to listenr1 but it seams to only return an empty list. I'm not sure why it's not appending, but I think I have misunderstood a fundamental part of…
2
votes
0 answers

Creation of Huffman File for compression c++

Good morning. I created a huffman tree in c++ and it's perfectly working. If I take a simple string from a file and put that on my huffman tree. This is the original text: Ciao sono un esempio di algoritmo di huffman! At the end of the compression…
Matta
  • 21
  • 1
2
votes
2 answers

Is DEFLATE used in gzip and png compression the same?

I read about gzip compression and png image compression and they both use DEFLATE alghorithm, but I'm not sure that the implementation of that algorithm is the same. Also, if it's the same algorithm, then what is the difference between those…
Maja K
  • 31
  • 3
2
votes
1 answer

Why is huffman encoded text bigger than actual text?

I am trying to understand how Huffman coding works and it is supposed to compress data to take less memory than actual text but when I encode for example "Text to be encoded" which has 18 characters the result I get is…
outbeyond
  • 35
  • 7
2
votes
3 answers

Writing bits to file?

I'm trying to implement a Huffman tree. Content of my simple .txt file that I want to do a simple test: aaaaabbbbccd Frequencies of characters: a:5, b:4, c:2, d:1 Code Table: (Data type of 1s and 0s: string) a:0 d:100 c:101 b:11 Result…
Murat
  • 79
  • 2
  • 10
2
votes
0 answers

Create code dictionary for Huffman Tree in PYTHON

I am working on implementing a huffman tree. I am having trouble generating the code dictionary for the tree. Here is what I have so far: class HuffmanNode: def __init__(self, char, freq): self.char = char self.freq = freq …
Toan Pham
  • 93
  • 8
2
votes
1 answer

Can a huffman tree enconding be different from one person to anoher?

I need to make a huffman tree for a college project, but I am really confused about how it works.I implemented the coding part of the huffman tree but it is different from http://huffman.ooz.ie/ all the time. It can be different from one person…
Danielman
  • 53
  • 1
  • 5
2
votes
0 answers

Huffman tree node doesn't append code to his son

My Huffman algorithm is working until I have to generate code for each symbol in tree. I don't know what is wrong. So when I start program it generates code for each Node, but does not append code from father. Example: How it looks like null …
lucian24
  • 45
  • 6
2
votes
2 answers

huffman compressor/decompressor

The code has been updated to use unique_ptr and namespaces. NOTE: i tried to implement anonymous namespace inside of namespace huffman but it wont allow to separate the file into .cpp and .h. any critique on the current code is welcome. feel free to…
2
votes
0 answers

Recursive function is recursing further than it needs to

I am writing code that produces Huffman codes for sequences of symbols in a given alphabet. It does this through an algorithm that builds a Huffman tree of nodes. Each node either has a unique symbol from this alphabet and is a leaf node, or else…
KOB
  • 4,084
  • 9
  • 44
  • 88
2
votes
1 answer

How to handle '/n' ,'/t' and similar ascii keys while creating Huffman code

For my project, I have to compress a file using Huffman algorithm. I figured out most of the part, however I am having hard time dealing with other ASCII characters such as newlines, tabs, etc.This is what I have done so far, however I am not able…
Jay Patel
  • 33
  • 3
2
votes
3 answers

Are DC and AC coefficient magnitude not huffman compressed in JPEG?

According to what I have read: DC coefficient per block, we create a byte storing difference magnitude category as shown in Annex F Table F.1 of ITU-T T.81. The actual DC coefficient which stores a difference is stored in raw bits following this…
quantum231
  • 2,420
  • 3
  • 31
  • 53