C++ Question

You need to develop the decoder for a new compression algorithm to evaluate the effectiveness of Elias-Gamma encoding for larger integer values. The proposed compression algorithm works as follows:

  1. Determine the frequency of symbols in the message.

  2. Sort the alphabet symbols in descending order based on their frequency. If two or more symbols have the same frequency, sort them according to lexicographical order (ascending based on ASCII value).

  3. Create the encoded message by appending the positions of the symbols (based on the sorted alphabet) in the original message. Since Elias-Gamma encoding is used to represent the positions, the values for the positions start from one.

Given the following original message: AACABDDADABC

The alphabet is sorted as A, D, B, and C, and the positions in the encoded message are: 1, 2, 4, 8, 10, 6, 7, 9, 5, 11, 3, and 12 (represented as Elias-Gamma codes).

Your decoder takes the following information as input from the standard input (STDIN):

  1. An integer representing the alphabet size (m).

  2. m symbols. Each symbol is represented by a single character and an integer value indicating its frequency.

  3. A binary string with positions encoded using Elias-Gamma code. The position values are stored according to the order of symbols in the sorted alphabet.

For this assignment, you will create a multithreaded program to find the positions of the symbols in the original message, reconstruct the original message (based on the encoded message), and determine the number of bits required to represent the positions using Elias-Gamma encoding.

Given the following input:

4
A 5
C 2
B 2
D 3
10100010000010000001010001100011100010010010100010110110001100

The expected output is:

Symbol: A, Frequency: 5
Positions: 0 1 3 7 9
Bits to represent the position(s): 23

Symbol: D, Frequency: 3
Positions: 5 6 8
Bits to represent the position(s): 17

Symbol: B, Frequency: 2
Positions: 4 10
Bits to represent the position(s): 12

Symbol: C, Frequency: 2
Positions: 2 11
Bits to represent the position(s): 10

Decoded message: AACABDDADABC

Process:

Your solution must execute the following steps:

  • Read the input lines from STDIN.

    • Create m POSIX threads (where m is the alphabet size). Each child thread performs the following tasks:

– Receives the encoded message, the symbol to decode, and the memory location to store the decoding results.

– Determines the positions of the assigned symbol in the original message.

– Calculates the number of bits used to represent the symbol’s position using Elias Gamma encoding.

– Stores the assigned symbol’s information in a memory location accessible by the main thread.

– Stores the assigned symbol, using the determined positions, into the memory address shared with the main thread that contains the decoded message.

  • Print the information for each symbol to STDOUT (sorted according to the compression algorithm rules).

  • Print the decoded message.

Notes:

  • The position values for the symbols must start from one (not from zero), because Elias Gamma encoding can only represent positive integers starting from one.

  • You can safely assume that the input will always be in the proper format.

  • You must use the output statement format shown in the example above.

  • You can define additional functions if needed.

  • You must take full advantage of multithreading.

  • You must present code that is readable and has comments explaining the logic of your solution. A 10% penalty will be applied to submissions that do not follow this guideline.

  • You cannot use global variables. A 100% penalty will be applied to submissions using global variables.

  • Not using multiple POSIX threads (the pthread.h library) to implement your solution will result in a 100% penalty. DO NOT USE THE THREAD LIBRARY FROM C++.

  • A penalty of 100% will be applied to solutions that do not compile.

  • A penalty of 100% will be applied to solutions that hardcode the output.

Assignment rubric:

  • Correct output: 10 points per test case (20 points total).

  • Correct implementation of the thread function: 30 points.

  • Taking full advantage of multithreading (no pthread_join or sleep in the same loop as pthread_create): 30 points.

  • Creating the correct number of threads: 10 points.

  • Having clean and commented code: 10 points.

Penalties:

  1. Presenting a solution that does not compile: -100 points.

  2. Not using POSIX threads: -100 points.

  3. Hardcoding the output: -100 points.

  4. Using global variables: -100 points.

  5. Using AI tools without following the rules stated in the syllabus: -100 points.

    the rules in the syllabus mention that you are only allowed to use AI tools to help understand why your solution isn’t working, and you must include a comment in the AI-generated code section explaining the problem the tool addressed.

Requirements:

Calculate the price of your order

Select your paper details and see how much our professional writing services will cost.

We`ll send you the first draft for approval by at
Price: $36
  • Freebies
  • Format
  • Formatting (MLA, APA, Chicago, custom, etc.)
  • Title page & bibliography
  • 24/7 customer support
  • Amendments to your paper when they are needed
  • Chat with your writer
  • 275 word/double-spaced page
  • 12 point Arial/Times New Roman
  • Double, single, and custom spacing
  • We care about originality

    Our custom human-written papers from top essay writers are always free from plagiarism.

  • We protect your privacy

    Your data and payment info stay secured every time you get our help from an essay writer.

  • You control your money

    Your money is safe with us. If your plans change, you can get it sent back to your card.

How it works

  1. 1
    You give us the details
    Complete a brief order form to tell us what kind of paper you need.
  2. 2
    We find you a top writer
    One of the best experts in your discipline starts working on your essay.
  3. 3
    You get the paper done
    Enjoy writing that meets your demands and high academic standards!

Samples from our advanced writers

Check out some essay pieces from our best essay writers before your place an order. They will help you better understand what our service can do for you.

  • Essay (any type)
    Direct Social Work Practice and Helping Process
    Undergrad. (yrs 3-4)
    Social Work and Human Services
    APA

Get your own paper from top experts

Order now

Perks of our essay writing service

We offer more than just hand-crafted papers customized for you. Here are more of our greatest perks.

  • Swift delivery
    Our writing service can deliver your short and urgent papers in just 4 hours!
  • Professional touch
    We find you a pro writer who knows all the ins and outs of your subject.
  • Easy order placing/tracking
    Create a new order and check on its progress at any time in your dashboard.
  • Help with any kind of paper
    Need a PhD thesis, research project, or a two-page essay? For you, we can do it all.
  • Experts in 80+ subjects
    Our pro writers can help you with anything, from nursing to business studies.
  • Calculations and code
    We also do math, write code, and solve problems in 30+ STEM disciplines.

Frequently asked questions

Get instant answers to the questions that students ask most often.

See full FAQ
  • How do you find the best essay writer for me?

    Our professional writing service focuses on giving you the right specialist so the one assigned will have the knowledge about the right topic. However, if you’ve used our essay service before, you can ask us to assign you the expert writer who used to complete papers for you in the past. We can easily do so if the specialist in question is available at the moment.

    If you’re ordering from our essay writing service for the first time, we will assign you a suitable expert ourselves and ensure that your academic essay writer is a pro. Moreover, let us know how complex your assignment is so that we can find the best match for your order.

    We’ve hired the best writers in 80+ academic subjects to complete any paper you need. As soon as we hear, “Write my essays,” our support team assigns you the writer who understands your needs and subject.

    In case you need to make sure we’ve picked a great specialist to deal with your paper, you can chat with the expert writers directly. We do our best to make sure you’re happy with the writer we’ve selected for you.

  • How can you prove that your paper writing service is not a scam?

    We have been selling original essays for more than 15 years. To prove that we are a trustworthy custom essay writing company, we provide quick delivery and a money-back guarantee. If we can’t complete your paper for any reason, we’ll send your money back to the credit card. We want to deliver the finest services, so you can decide if the paper is good enough; from our side, we’ll edit it according to your primary requirements to make the writing perfect. Our online paper writing service is about both giving you the materials you need when you need them and ensuring that your private data is safe. Check out our guarantees to see how we control the quality of your assignment and protect you as a customer.

See full FAQ

Take your studies to the next level with our experienced specialists