Count duplicate words in a file

Purpose: find the number of all words in a file. file contains more than 1000 words

My approach: use HashMap<String,Integer>()to store and count the number of times each word appears in a file.

Question: Would HashMap()it be better or better to use a binary tree to provide a faster search, since the file has a large number of words?

Or is there a better way to do this?

HashMap will lead to a large amount of memory overhead, which is undesirable.

+3
source share
5 answers

So, are you looking for different words?

The most effective framework I can think of is Trie

: Google patricia-trie

Mitch Wheat - , HashMap ( ... HashMap, , )

+5

1000 - 10000 .

.

+5

​​ Perl/PHP. .

+1

A HashMap .

HashMap !

0
  • , , "Trie", , . node Trie "" , . ( , , ).

  • , , HashMap, Map Integer = > Integer - "" - - count. - .

0

Source: https://habr.com/ru/post/1769739/


All Articles