Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Step: 3

blur-text-image

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

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

3. You can gain power by making others feel important.

Answered: 1 week ago

Question

Write down the circumstances in which you led.

Answered: 1 week ago