Question: 2. Write a program that reads a text file from the same directory that your main program is stored and then perform some operations on

 2. Write a program that reads a text file from the

2. Write a program that reads a text file from the same directory that your main program is stored and then perform some operations on it. Concretely: 1) Your program reads from the console (1) the name of the file (test.txt for instance) and (2) an integer k. Your program then reads the file. While reading the file (NOT after the file has been read), you need to count the occurrence of each word. Note that "cat" and "cats" could be considered as two different words. In addition, special characters such as /*? are all separate words. For instance, "I'm having some headache" has six words ("T", **", "m", "having, some, headache"). Once the file-reading is completed, your program should output the EXACT (not approximate) the top k most frequent words. In case there are ties in terms of word frequencies, return all. You must ensure that your program runs as efficiently as possible because, in reality, your program might be reading a file with billions of words and a very large kvalue. Please provide the algorithmic complexity of your code. 2. Write a program that reads a text file from the same directory that your main program is stored and then perform some operations on it. Concretely: 1) Your program reads from the console (1) the name of the file (test.txt for instance) and (2) an integer k. Your program then reads the file. While reading the file (NOT after the file has been read), you need to count the occurrence of each word. Note that "cat" and "cats" could be considered as two different words. In addition, special characters such as /*? are all separate words. For instance, "I'm having some headache" has six words ("T", **", "m", "having, some, headache"). Once the file-reading is completed, your program should output the EXACT (not approximate) the top k most frequent words. In case there are ties in terms of word frequencies, return all. You must ensure that your program runs as efficiently as possible because, in reality, your program might be reading a file with billions of words and a very large kvalue. Please provide the algorithmic complexity of your code

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!