Skip to content

feat: add Huffman coding algorithm to greedy_approach#1570

Open
DiogoRibeiro7 wants to merge 1 commit intoTheAlgorithms:masterfrom
DiogoRibeiro7:feat/huffman-coding
Open

feat: add Huffman coding algorithm to greedy_approach#1570
DiogoRibeiro7 wants to merge 1 commit intoTheAlgorithms:masterfrom
DiogoRibeiro7:feat/huffman-coding

Conversation

@DiogoRibeiro7
Copy link
Copy Markdown

Description of Change

Add a Huffman coding compression algorithm implementation to the greedy_approach/ directory. Huffman coding is a classic greedy algorithm that assigns variable-length binary codes to characters based on their frequencies, producing an optimal prefix-free code.

The implementation includes:

  • A min-heap (priority queue) for building the Huffman tree
  • Tree construction by repeatedly merging the two lowest-frequency nodes
  • Recursive code generation via tree traversal (left = '0', right = '1')
  • Special case handling for single unique character inputs
  • Interactive mode that displays character codes and compression statistics
  • 5 self-test cases covering basic encoding, prefix-free property, single character, equal frequency, and optimality

Also adds the missing CMakeLists.txt for the greedy_approach/ directory and registers it in the root CMakeLists.txt.

References

N/A - new algorithm addition, no prior issue or PR.

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes: Adds greedy_approach/huffman.c with full Doxygen documentation, min-heap based tree construction, and 5 assert-based tests. Also creates greedy_approach/CMakeLists.txt which was previously missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant