Question
I have some psuedocode but need to convert it to C++. Any help would be appreciated. Code: struct wordPair { // define a structure for
I have some psuedocode but need to convert it to C++. Any help would be appreciated.
Code:
struct wordPair { // define a structure for word pairs
string word1; // defining words
string word2;
int count; // declaring variable
};
input: article // code input
output: words paired most frequently // code output
findFrequentWordPair(article):
vector
sentences[]=splitSentence(article); //organizes into sentences
for each sentence within sentences:
words[]=wordIdentifier(sentence); // splits sentences into words
for kk=0:words.length()-2:
newWordPair=new; // creates a new word pair
wordPair(words[kk], words[kk+1],1); // calls word pair
flag=0;
for pair in vv: // checking to see if pair exists
if pair = newWordPair:
increment count of pair;
flag=1;
break;
if flag = 0; // if new pair is not present
vv.push_back(newWordPair);
maxFreq = 0;
for kk=0:vv.size()-1: // find highest frequency
if (vv[kk].count>maxFreq)
maxFreq=vv[kk].count; // if greater, update value
for (vv[kk].count = maxFreq):
print vv[kk];
___________________________________________________
getFrequentProductPairs (products, transactions, min_freq):
frequentPairs = []; // list of frequent pairs
frequencyMap = {0}; // frequency map - stores the count of each product pairs all initialized to 0
minProductCount = min_freq*(product) // count of number of times product/product pair has to appear to become frequent for (transaction of transactions) {
transactionBinaryString = convert_to_binary(products, transactions)
permutations = get_binary_string_permutations(transactionBinaryString)
for(permutation of permutations) : permutationIndex = convert_binary_string_to_int(permutation) // convert the binary string to index so that it can be incremented
frequencyMap[permutationIndex]++
for(productPairCount of frequencyMap): if(productPairCount > minProductCount)
products = convert_index_to_products_list(productPairCount) //converts the index back to the products array frequentPairs.push(products) // pushes the products to frequent items list
return frequentPairs;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started