Java icon indicating copy to clipboard operation
Java copied to clipboard

[FEATURE REQUEST] Huffman Coding Compression Algorithm

Open Shewale41 opened this issue 1 month ago • 2 comments

What would you like to Propose?

Title: Add Huffman Coding for Lossless Compression and Decompression


🧠 Overview

Implement Huffman Coding, a greedy algorithm used in file compression (ZIP, JPEG, etc.) that encodes data based on character frequency.

🧩 Problem Description

Given a string, generate prefix-free binary codes for each character based on frequency and compress the data efficiently.

📂 Implementation Details

  • Folder: src/main/java/com/thealgorithms/compression/
  • Filename: HuffmanCoding.java
  • Approach:
    • Count frequency of each character.
    • Build a min-heap tree based on frequency.
    • Generate variable-length codes (shorter for frequent characters).
    • Support encoding and decoding.

✅ Expected Deliverables

  • Complete implementation with encoder and decoder functions.
  • Example usage in main().
  • Unit tests verifying encoding-decoding accuracy.
  • Complexity analysis (O(n log n)).

🧑‍💻 Additional Notes

This algorithm is a foundational data compression technique that fits perfectly into the repository’s educational goals.

Issue details

🧩 Problem Description

Given a string, generate prefix-free binary codes for each character based on frequency and compress the data efficiently.

Additional Information

No response

Shewale41 avatar Oct 25 '25 13:10 Shewale41