Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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; //creating a vector to store word pairs

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

what is the main reason DDR 4 ram is faster than DDR 3 ram?

Answered: 1 week ago

Question

=+j Explain the essential nature of repatriation.

Answered: 1 week ago