Find word with maximum number of occurrences

后端 未结 2 1358
轮回少年
轮回少年 2021-01-07 02:49

What is the most optimal way (algorithm) to search for the word that has the maximum number of occurrences in a document?

2条回答
  •  梦谈多话
    2021-01-07 03:44

    1. Scan the document once, keeping a count of how many times you have seen every unique word (perhaps using a hashtable or a tree to do this).
    2. While performing step 1, keep track of the word that has the highest count of all words seen so far.

提交回复
热议问题