Code Monkey home page Code Monkey logo

huffman_coding's Introduction

Huffman Coding

Given a frequency data, produces huffman codes for the unique messages.

  • Node.java: DS for storing huffman tree
  • PairNode.java: DS used in PairingHeap.java
  • BinaryHeap.java: To implement binary heap
  • PairingHeap.java: To implement pairing heap
  • D_aryHeap.java: To implement D-ary heap. For eg. 4-way heap.
  • Gen_huffman_code.java: To comapre the performance of above mentioned priority queues for huffman coding.

Usage:

~:src$ java Gen_huffman_code ../sample_input_large.txt 
Reading input file ... Building Freq Table ... Done.
Building Huffman Tree using Binary Heap ... 
Run:1.. 2.. 3.. 4.. 5.. 6.. 7.. 8.. 9.. 10..  Done
Average Time: 1663.0
Building Huffman Tree using Pairing Heap ... 
Run:1.. 2.. 3.. 4.. 5.. 6.. 7.. 8.. 9.. 10..  Done
Average Time: 3417.0
Building Huffman Tree using 4-ary Heap ... 
Run:1.. 2.. 3.. 4.. 5.. 6.. 7.. 8.. 9.. 10..  Done
Average Time: 1291.0

It is found that 4-ary heap is the fastest. So later encoding is done using 4-ary heap.

  • encoder.java: Produces code_table.txt containing codes for all the unique messages; and encoded.bin, which is the binary file for the codes corresponding to the input file.

Usage:

~:src$ java encoder ../sample_input_large.txt 
Reading input file ... 
Building Freq Table ... 
Building huffman tree... Done.
Generating code_table.txt .. Done.
Generating encoded.bin .. Done.

As a proof of concept, we will reconstruct our input using code_table.txt and encoded.bin

  • decoder.java: Takes in input encoded.bin and code_table.txt and produces decoded.txt which is exactly the same as sample_input_large.txt as used in encoder.

Usage:

~:src$ java decoder encoded.bin code_table.txt 
Building huffman tree from code_table.txt .. 
Reading code_table.txt .. Done.
Reading encoded.bin .. Done.
Generating decoded.txt .. Done.

Do diff decoded.txt ../sample_input_large.txt to check correctness.

Clone repository and make:

~:$ git clone https://github.com/vishalkg/huffman_coding.git
~:$ cd huffman_coding/src
~:src$ make

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.