Question: Please code in C + + , You will need to use PriorityQueue and Hashing here; so , if you have not read how to

Please code in C++,
You will need to use PriorityQueue and Hashing here; so, if you have not read how to use them,
check out Section 2.2 and Section 2.3.
In Java or C#, to create a BinaryTreeNode with character c and value v, the syntax is: BinaryTreeNode node = new BinaryTreeNode(c, v); In C++, to create a BinaryTreeNode with character
c and value v, the syntax is: BinaryTreeNode *node = new BinaryTreeNode(c, v);
Let frequenceM ap (class variable) contain the mapping of each character (in the alphabet)
to its frequency (number of occurrences in the message). Implement the encode, buildTree, and
createTable methods using the pseudo-codes.
Psuedo-Code for Encode function:
root = buildTree()
createTable(root,);
Iterate over the frequency-map and do the following:
let c be the current character (key) in the frequency-map
let f be the current frequency (value) in the frequency-map
let code = getEncoding(c) be the codeword for the character
encodingLength = encodingLength + f length of code
tableSize = tableSize + length of code +8
Psuedo-code for BuildTree function:
Create a BinaryTreeNode minimum priority queue P Q
Iterate over the frequency-map and do the following:
let c be the current character (key) in the frequency-map
let f be the current frequency (value) in the frequency-map
create a binary tree node z for the character c and value f
add z to PQ
While P Q has more than than 1 node, do the following:
get the minimum binary tree node min from PQ and remove it
get the second minimum binary tree node secondM in from PQ and remove it
create a binary tree node z with the character \0
and value the sum of the values
of min and secondM in
assign min to be the left child of z and secondM in to be the right child of z
add z to PQ
return the minimum from PQ
Psuedo-code for CreateTable function
If nodes left child and right child are both null, then insert nodes character as key
and the string encoding as value into the hashtable charToEncodingMapping
Else do the following:
If nodes left child = null, createTable(nodes left child, encoding +0)
If nodes right child = null, createTable(nodes right child, encoding +1)
Psuedo-code for Decode function:
Let encode = and decodedMsg =
Let n be the length of the encoded message
For i =0 to i < n, do the following:
encode = encode + the character at index i of encodedMsg
If the hashtable encodingToCharMapping contains the key encode, then
let c be the value for the key encode in encodingToCharMapping
decodedMsg = decodedMsg + c
encode =;
return decodedMsg
Complete the functions as mentioned below in C++
#include
#include
#include
#include "BinaryTreeNode.h"
#include "BinaryTreeNodeComparator.h"
#ifndef HUFFMANENCODER_H_
#define HUFFMANENCODER_H_
class HuffmanEncoder {
int encodingLength;
int tableSize;
unordered_map charToEncodingMapping;
unordered_map frequencyMap;
public:
HuffmanEncoder(unordered_map freqMap){
frequencyMap = freqMap;
encodingLength = tableSize =0;
}
~HuffmanEncoder(){
}
void encode()
{// complete this method
}
private:
BinaryTreeNode *buildTree()
{// complete this method
}
void createTable(BinaryTreeNode *node, string encoding)
{// complete this method
}
public:
string getEncoding(char c)
{
return charToEncodingMapping[c];
}
int getTableSize()
{
return tableSize;
}
int getEncodingLength()
{
return encodingLength;
}
};
Complete functions in this class
#include
#include
using namespace std;
#ifndef HUFFMANDECODER_H_
#define HUFFMANDECODER_H_
class HuffmanDecoder {
public:
static string decode(string encodedMsg, unordered_map encodingToCharMapping)
{
// complete this method
}
};
#endif /* HUFFMANDECODER_H_*/
Thank you for your assistance!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!