MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / main

Method main

src/main/java/com/thealgorithms/others/Huffman.java:193–210  ·  view source on GitHub ↗

Demonstrates the Huffman coding algorithm with sample data. @param args command line arguments (not used)

(String[] args)

Source from the content-addressed store, hash-verified

191 * @param args command line arguments (not used)
192 */
193 public static void main(String[] args) {
194 // Sample characters and their frequencies
195 char[] charArray = {'a', 'b', 'c', 'd', 'e', 'f'};
196 int[] charFreq = {5, 9, 12, 13, 16, 45};
197
198 System.out.println("Characters: a, b, c, d, e, f");
199 System.out.println("Frequencies: 5, 9, 12, 13, 16, 45");
200 System.out.println("\nHuffman Codes:");
201
202 // Build Huffman tree
203 HuffmanNode root = buildHuffmanTree(charArray, charFreq);
204
205 // Generate and print Huffman codes
206 Map<Character, String> codes = generateCodes(root);
207 for (Map.Entry<Character, String> entry : codes.entrySet()) {
208 System.out.println(entry.getKey() + ": " + entry.getValue());
209 }
210 }
211}

Callers

nothing calls this directly

Calls 4

buildHuffmanTreeMethod · 0.95
generateCodesMethod · 0.95
getKeyMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected