CC150 19.8

19.8 Design a method to find the frequency of occurrences of any given word in a book.

How big the book is?

split words into different smaller files:

File[] files;
for (String word : book.words())
{
  int fileIndex = hash(word) % 1000; // Say put into 1000 smaller files.
  files[fileIndex].save(word); // Buffer and save.
}

Then for each file
for (File file : files)
{
  // Use hashmap to calculate occurances.
}

// Then given any word, find the suitable hashmap. and find the value.


你可能感兴趣的:(interview)