Added the Huffman Coding using java#6587
Closed
PriyanshuPaul79 wants to merge 3 commits intoTheAlgorithms:masterfrom
Closed
Added the Huffman Coding using java#6587PriyanshuPaul79 wants to merge 3 commits intoTheAlgorithms:masterfrom
PriyanshuPaul79 wants to merge 3 commits intoTheAlgorithms:masterfrom
Conversation
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.
Member
|
@PriyanshuPaul79 Please fix the failing workflows so I can start the review. |
|
This pull request has been automatically closed because its workflows or checks failed and it has been inactive for more than 14 days. Please fix the workflows and reopen if you'd like to continue. Merging from main/master alone does not count as activity. |
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
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.
HuffmanNodeClassThis inner class represents a node in the Huffman Tree.
frequency(how many times the character appears), thecharacteritself (only for leaf nodes), and pointers to theleftandrightchild nodes.compareToMethod: Implements theComparableinterface to allow a PriorityQueue to order nodes based on their frequency. Lower frequency nodes have higher priority for extraction.HuffmanCodingClass1. Building the Tree (
buildTreemethod)The main goal of this method is to construct the optimal binary tree for encoding.
textto count the occurrences of every character, storing them in aMap<Character, Integer>.HuffmanNode(a leaf node), and all are added to a PriorityQueue (pq).generateCodeshelper method.2. Generating Codes (
generateCodesmethod)This is a recursive method that performs a traversal (typically a Depth First Search) of the Huffman Tree:
huffmanCodesmap.3. Encoding (
encodemethod)This method iterates through the input
textand replaces each character with its corresponding binary code retrieved from thehuffmanCodesmap.4. Decoding (
decodemethod)This method reconstructs the original text from the binary string:
Example Execution (from
mainmethod)The example uses the string:
"huffman coding is a lossless data compression algorithm"Original Text == Decoded Text.