Word Frequency - Binary Tree - C++ data file: http://pastebin.com/q4ZK46RQ Given
ID: 3927615 • Letter: W
Question
Word Frequency - Binary Tree - C++
data file: http://pastebin.com/q4ZK46RQ
Given an arbitrarily long list of unordered words with an arbitrary number of different values (words) appearing in it, determine and print the marginal distribution for this list of words. That is, count how many times each different value appears in the list and then print out each value along with its count and its marginal distribution. The output should be arranged from the smallest to the largest value (in alphabetical order). (Print the first 100 words only for output.)
You are to use binary tree that will handle single words. The binary tree is to be maintained as an ordered tree.
Note: ‘the’ and ‘The’ are the same words so there should be only one entry into the tree.
Now we need to delete the most common words used. Delete 15% of the most common words found in this text. Now compute their NEW relative values for the new set of words and print the list of words left in the data structure. (Again print out only the first 100 words.) (15% of the words?: If I had 100 words in my tree, then 15 words would be deleted.)
Example
Word Absolute Relative
Smith 677 1.832 %
Jones 88 3.548%
Explanation / Answer
#include #include #include #include using namespace std; int no_input(); int no_output(); ifstream infile; ofstream outfile; int no_input() { if(!infile) { cout count = 1; tmp->leftChild = NULL; tmp->rightChild = NULL; return tmp; } void insert(treeNode *current, char *wrdPTR) { treeNode *previous; treeNode *tmp; totalWords++; *wrdPTR = toupper(*wrdPTR); //ensure all words start uppercase if(current == NULL) { //start tree root = myNewNode(); totalUnique++; root->word = wrdPTR; return; } while(current != NULL) { //search routine if(wrdPTR word) { previous = current; current = current->leftChild; } else if(wrdPTR > current->word) { previous = current; current = current->rightChild; } else //if duplicate word, stop search break; } if(current != NULL && wrdPTR == current->word) { current->count++; //if duplicate, increment count & return return; } tmp = myNewNode(); totalUnique++; tmp->word = wrdPTR; if(wrdPTR word) previous->leftChild = tmp; else if(wrdPTR > previous->word) previous->rightChild = tmp; return; } treeNode* getroot() { return root; } int gettotal() { return totalWords; } int getunique() { return totalUnique; } void printPreorder(treeNode *current) { if(current == NULL) return; else { outfile word.length() < 8) outfile word.length() < 16) outfileRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.