Coder Social home page Coder Social logo

huffman-encoding's Introduction

Huffman Encoding

This project implements Huffman Encoding, a data compression algorithm that is used to reduce the size of data by assigning shorter codes to frequently occurring characters. It utilizes a priority queue and a binary tree to build a variable-length prefix code for each character in the input string.

Features

  • Count the frequency of characters in the input string.
  • Build a Huffman tree based on the character frequencies.
  • Generate a lookup table of characters and their corresponding Huffman codes.
  • Encode a given string using Huffman codes.
  • Decode a given bit sequence using the Huffman tree.

Getting Started

Prerequisites

To run this project, you need to have a C++ compiler installed on your machine.

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/huffman-encoding.git
  2. Compile the source code:

    g++ huffman_encoding.cpp -o huffman_encoding

Usage

  1. Run the executable:

    ./huffman_encoding
  2. Enter the string you want to encode when prompted.

  3. The program will display the Huffman codes for each character in the input string, followed by the encoded string.

  4. The program will then decode the encoded string and display the original string.

Example

Enter the string to be encoded: hello
HUFFMAN CODE:
e: 0
l: 10
h: 110
o: 111

Encoded String: 1100101111
Decoded String: hello

Contributing

Contributions are welcome! If you find any issues or want to add new features, feel free to open a pull request.

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.