I just need a working C code. I can do the rest of the questions, so no comments needed there.
Data Structure and Algorithm, Junhee Seok, Korea University Programming Assignment 4 Counting Words In this programming assignment, you will implement a program counting words of a text file. To count how many a word appears in a text document, we will use a map or associated array. Briefly, a map has keys and values. The key is an orderable unique value used to access the value. The value is the information we want to keep and update. For the details, please see the Wikipedia (https://en.wikipedia.org/wiki/Associative_array). In this assignment, a word is a key and its count is a value. A map can be implemented by a binary search tree. In the lecture note, a tree is constructed with elements, but for a map, a tree is constructed with keys and each tree node has an additional value field. The below is the tree node structure we will use. word is used to construct a tree. word variable is expected to have a string value. Strings are orderable. Two string can be compared by the lexicographical order. For example, “boy” is ahead of “girl”, which means “boy” is less than “girl” in the lexicographical order. You can compared two strings using strcmp() function of string.h. You may need to use other string function of C standard library such as strcpy() and strlen(). In this assignment, you need to implement the below functions. I provide codes that reads a text file and extract words. The words are stored in word_bank variable, from which you need to build a binary search tree via count_words(). You also need to implement the basic tree operations of insertion, deletion, finding, and calculating maximum depth, the number of nodes, and the sum of word counts. You also need to implement a printing function. Every operation is very similar with what we have discussed in the class except insertion. Whenever you see a word from a file, you need to insert the word to the tree. If the tree has no such a word, a new tree node is created and inserted. If the word already exists, its count is increased by 1. Data Structure and Algorithm, Junhee Seok, Korea University With your implementation, please answer the following questions. 1. What is data01_short_text.txt about? What is data03_long_text.txt about? This is more likely to be a liberal arts question, especially for engineers.^^ 2. Explain read_file() line-by-line. Explain how words are stored in word_bank. When “I love you” is in an input file, explain how the words are stored in word_bank.storage. And also explain how word_bank.words will keep the information of word strings. 3. Implement functions of the page 1. Briefly explain how these functions work. Provide the function codes and associated data types and variables if needed. The printing function should print the words and counts of the tree node in a preorder traversal. The printing position of a node should be properly indented. The example is shown in Test 1. 4. Run test1() and provide the screen shot. Ideally, your screen shot will be like the below. Please check the number of nodes, the sum of counts, and the maximum tree depth is correctly calculated, by comparing with your printed tree. Note that the tree structure and the maximum depth might be different according to your implementation. However, the number of nodes and the sum of counts should be identical. Data Structure and Algorithm, Junhee Seok, Korea University 5. Run test2() and provide the screen shot. Ideally, your screen shot will be like the below. Note that the tree structure and the maximum depth might be different according to your implementation. However, the number of nodes and the sum of counts should be identical. What are the children of “heart” in your result? What is the parent of “the”? Data Structure and Algorithm, Junhee Seok, Korea University 6. Run test3() and provide the screen shot. Ideally, your screen shot will be like the below. Note that the maximum depth might be different according to your implementation. However, the number of nodes and the sum of counts should be identical. 7. Run test4() and provide the screen shot. Ideally, your screen shot will be like the below. Briefly, explain the procedure of test4(). 8. Repeat problem 7 by setting the random seed as the last four digits of your student id. Provide the screen shot, too. Please submit two files: (1) Report: a single electronic file including answers of the questions, screen shots, source code in the format of doc, hwp or pdf. (2) main.c: a plain-text source code file that can generate the result of the report. Ideally, the screen shots can be reproduced with this file. Note that your assignment will be graded with only the report. So, if you do not include source codes in the report, you will not get scores. The plain-text source code will be considered when you have problems, for example, suspicion of the copy&paste or non-sense results. If the plain- text source code is different from codes on the report or it cannot reproduce the results on the report, then your grade will be 0. Please submit the above files through the blackboard system. If you have any question for this project assignment, please contact me or TA.