-
Notifications
You must be signed in to change notification settings - Fork 20.4k
Added the Huffman Coding using java #6587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@PriyanshuPaul79
PriyanshuPaul79
requested review from
DenizAltunkapan,
yanglbme and
alxkm
as code owners
October 2, 2025 12:29
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@ ## master #6587 +/- ## ============================================ - Coverage 75.50% 75.21% -0.29% Complexity 5688 5688 ============================================ Files 694 695 +1 Lines 19570 19645 +75 Branches 3791 3802 +11 ============================================ Hits 14776 14776 - Misses 4217 4292 +75 Partials 577 577 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Prevent instantiation of HuffmanCoding class.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The uploaded Java file implements the Huffman Coding algorithm, which is a lossless data compression technique.
Core Components and Functionality
The code defines the Huffman Coding process, including building the compression tree, generating the binary codes, and performing both encoding and decoding.
HuffmanNode
ClassThis inner class represents a node in the Huffman Tree.
frequency
(how many times the character appears), thecharacter
itself (only for leaf nodes), and pointers to theleft
andright
child nodes.compareTo
Method: Implements theComparable
interface to allow a PriorityQueue to order nodes based on their frequency. Lower frequency nodes have higher priority for extraction.HuffmanCoding
Class1. Building the Tree (
buildTree
method)The main goal of this method is to construct the optimal binary tree for encoding.
text
to count the occurrences of every character, storing them in aMap<Character, Integer>
.HuffmanNode
(a leaf node), and all are added to a PriorityQueue (pq
).generateCodes
helper method.2. Generating Codes (
generateCodes
method)This is a recursive method that performs a traversal (typically a Depth First Search) of the Huffman Tree:
huffmanCodes
map.3. Encoding (
encode
method)This method iterates through the input
text
and replaces each character with its corresponding binary code retrieved from thehuffmanCodes
map.4. Decoding (
decode
method)This method reconstructs the original text from the binary string:
Example Execution (from
main
method)The example uses the string:
"huffman coding is a lossless data compression algorithm"
Original Text == Decoded Text
.