0% found this document useful (0 votes)
13 views2 pages

Problem Statement

The document outlines a program that reads a text file to identify the most frequently occurring word and its count. It details the steps for reading the file, cleaning and counting the words, and handling edge cases such as empty files and punctuation. The expected output includes the most frequent word and its count, with considerations for time complexity in reading and storing words.

Uploaded by

physicstutormcq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Problem Statement

The document outlines a program that reads a text file to identify the most frequently occurring word and its count. It details the steps for reading the file, cleaning and counting the words, and handling edge cases such as empty files and punctuation. The expected output includes the most frequent word and its count, with considerations for time complexity in reading and storing words.

Uploaded by

physicstutormcq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Problem Statement:

Write a program that reads a text file, finds


the most frequently occurring word,
and prints it along with its count.

Example File (input.txt):


apple banana apple PinE. orange
Banana apple orange pine Banana pine
Orange "Pine" PIn'e. Pine!

Expected Output:
Most Frequent Word: pine
Count: 6
Explanation:

1. Read the file line by line using BufferedReader.

2. Extract words, convert them to lowercase, and clean them (removing


punctuation).

3. Use a HashMap to count occurrences of each word.

4. Find the word with the highest count. 5. Print the most frequent word and
its count.

Edge Cases Considered:

✔If the file is empty, print "No words found". ✔If multiple words have the
same frequency, it prints the first encountered one.

✔Handles punctuation and ignores case (treats "Apple" and "apple" as the
same).

Time Complexity:

.Reading the file: O(N) (N = number of words

in the file)

.Storing words in Hasimap: O(N)

You might also like