top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the Huffman algorithm?

+4 votes
207 views

What is the Huffman algorithm? How to implement it in C/C++

posted Jun 2, 2014 by Muskan

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes
 
Best answer

The Huffman algorithm is lossless compression algorithm where frequency of individual letters are used to compress the data. The idea behind the algorithm is that if you have some letters that are more frequent than others, it makes sense to use fewer bits to encode those letters than to encode the less frequent letters.

Example

HELLO WORLD

Letter Frequency 
H      1
E      1
L      3
O      2
Space  1  
W      1
R      1
D      1

In the above example we should use least number of bits for L, followed by O, followed by rest.

Check the following link which nicely describe the algorithm
http://www.cprogramming.com/tutorial/computersciencetheory/huffman.html

answer Jun 2, 2014 by Salil Agrawal
Similar Questions
+3 votes

http://en.wikipedia.org/wiki/Relational_database_management_system

There are Database Backup and restore utilities for RDBMS Systems.
The Backup program generates a (.Bak) Binary File as output which can later be restored in case the Database crashes.

What could be the Algorithm/s in database backup/s and restore programs ?. i.e. C/C++ Programming logic/Algorithm.

+7 votes

In lot of C++ code in my company I see extern C code something like

extern "C"
{
    int sum(int x, int y)
    {
        return x+y;
    }
}

Please explain the significance of this?

...