date = 2023-02-27
tags = ["compsci", "deno"]
title = "Huffman Coding Deno program"

Huffman Coding Deno program

deno run https://jaeyoung.se/jaese/huffman.js

huffman.js is another Deno program I made for fun which performs the Huffman coding algorithm on given text and prints the resulting Huffman table.

Here is an example run. Source text can be given from stdin with the '--stdin' flag.

$ deno run https://jaeyoung.se/jaese/huffman.js
huffman_cli.ts generates and prints a binary tree representation of a Huffman code given a source text.

Pass --help to see the command line options.

Please enter source text: Hello, world!
Huffman code:
├─ 0: (0.400)
│  ├─ 0: O (0.200)
│  └─ 1: (0.200)
│     ├─ 0: R (0.100)
│     └─ 1: (0.100)
│        └─ 1: W (0.100)
└─ 1: (0.600)
   ├─ 0: L (0.300)
   └─ 1: (0.300)
      ├─ 0: E (0.100)
      └─ 1: (0.200)
         ├─ 0: D (0.100)
         └─ 1: H (0.100)

Comments

Leave a comment