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

后端 未结 15 1704
予麋鹿
予麋鹿 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:59

    Depending on the size of the input data, it may or may not be a good idea to keep a HashMap. Say for instance, our hash-map is too big to fit into main memory. This can cause a very high number of memory transfers as most hash-map implementations need random access and would not be very good on the cache.

    In such cases sorting the input data would be a better solution.

提交回复
热议问题