Find the k most frequent words from a file
Case 1 - Consider the file is not big
The question can be described as: Input: A positive integer K and a text file which can stay in-memory. The text can actually be viewed as word sequence. So we don’t have to worry about how to break down it into word sequence. Output: The most frequent K words in the text.
My thinking is like this.
use a Hash table to record all words’ frequency while traverse the whole word sequence.
[Read More]