Given a file, find the ten most frequently occurring words as efficiently as possible

后端 未结 15 1691
予麋鹿
予麋鹿 2020-12-12 13:26

This is apparently an interview question (found it in a collection of interview questions), but even if it\'s not it\'s pretty cool.

We are told to do this efficien

15条回答
  •  眼角桃花
    2020-12-12 13:51

    I think this is a typical application of counting sort since the sum of occurrences of each word is equal to the total number of words. A hash table with a counting sort should do the job in a time proportional to the number of words.

提交回复
热议问题