Provide necessary codings

Learning Goal: I’m working on a c++ multi-part question and need an explanation and answer to help me learn.

Please follow all the instructions. Make sure the code compiles. It has to be in C++


Similarity Threshold: 95%


Problem:

For this assignment, you will create a multithreaded Huffman decompressor (https://en.wikipedia.org/wiki/Huffman_coding).

To generate the Huffman tree, you must execute the following steps:

  1. Read the alphabet information from an input file.
    • Each line of the input file contains information (character and frequency) about a symbol from the alphabet. The input file format is as follows (each line as:
      • A char representing the symbol.
      • An integer representing the frequency of the symbol.
  2. Arrange the symbols based on their frequencies. If two or more symbols have the same frequency, they will be sorted based on their ASCII value.
  3. Execute the Huffman algorithm to generate the tree. To guarantee that your solution generates the expected output from the test cases, every time you generate an internal node of the tree, you must insert this node into the queue of nodes as the lowest node based on its frequency. Additionally, you must label the edge to the left child as 0 and the edge to the right child as 1.

After generating the Huffman Tree, your solution reads a compressed file with the following format:

  1. A string representing the binary code of the symbol.
  2. A list of n integers (where n is the frequency of the symbol) representing the positions where the symbol appears in the message.

The compressed file has m lines (where m is the number of symbols in the alphabet).

Your solution must create m POSIX threads to decompress the file and print the original message.

Process:

Given the following input file with the information about the alphabet:

A 3C 3B 1D 2

And the following compressed file:

11 1 3 50 0 2 4101 6 8100 7

Your solution must execute the following steps:

  • Read from STDIN the filename (string) of the input file.
  • Read the alphabet information from the input file.
  • Generate the Huffman Tree. Given the input file above, the generated Huffman Tree is:

Huffman Tree from input file

  • Print the Huffman codes from the generated tree. The symbols information (leaf nodes) must be printed from left to right

Given the previous Huffman tree, the expected output is:

Symbol: C, Frequency: 3, Code: 0Symbol: B, Frequency: 1, Code: 100Symbol: D, Frequency: 2, Code: 101Symbol: A, Frequency: 3, Code: 11
  • Read from STDIN the filename (string) of the compressed file.
  • Read the information from the compressed file.
  • Create n POSIX threads (where n is the number of symbols to decompress). Each child thread executes the following tasks:

– Receives the Huffman tree and the information about the symbol to decompress (binary code and list of positions) from the main thread.

– Stores the decompressed character (as many times as needed based on the list of positions) on a memory location accessible by the main thread.

  • Print the original message. For the compressed file above, the expected original message is:
Original message: CACACADBD

NOTES:

  • Not using multiple POSIX threads to implement your solution will translate into a penalty of 100%.
  • A penalty of 100% will be applied to solutions that do not compile.
  • The huffmanTree.h and huffmanTree.cpp files are optional (if you want to implement an OOP solution).
  • You must use the output statement format based on the example above.
  • You can safely assume that the input will always be valid.

Requested files

Requested files

main.cpp

1

// Write your program here

huffmanTree.h

1

// Write the definition of the huffmanTree class here.

huffmanTree.cpp

1

// Write the implementation of the member functions of the huffmanTree class here.

Do you need help with this paper? 🏆 - Let us help you write it!

Why Choose Our Essay Writing Service?

  • ✅ Original writing: Our expert writers will write each paper from scratch, ensuring complete originality, zero plagiarism and AI free content.
  • ✅ Expert Writers: Our seasoned professionals are ready to deliver top-quality papers tailored to your needs.
  • ✅ Guaranteed Good Grades: Impress your professors with outstanding work.
  • ✅ Fast Turnaround: Need it urgently? We've got you covered!
  • ✅ 100% Confidentiality: Customer privacy is our number one priority. Your identity is anonymous to our writers.
🎓 Why wait? Let us help you succeed! Our Writers are waiting..

Get started

Starts at $9 /page

How our paper writing service works

It's very simple!

  • Fill out the order form

    Complete the order form by providing as much information as possible, and then click the submit button.

  • Choose writer

    Select your preferred writer for the project, or let us assign the best writer for you.

  • Add funds

    Allocate funds to your wallet. You can release these funds to the writer incrementally, after each section is completed and meets your expected quality.

  • Ready

    Download the finished work. Review the paper and request free edits if needed. Optionally, rate the writer and leave a review.