3 ms·
What is the tree (trie?) structure and sorting-and-aggregating that you mean? The tree structure: Put all the unique words into a tree. You could use a trie,
by cperciva 18y ago
What is the tree (trie?) structure and sorting-and-aggregating that you mean?
The tree structure: Put all the unique words into a tree. You could use a trie, but considering how dense the tree is likely to end up, a traditional split-26-ways-on-each-byte tree would probably work just as well.
The sorting-and-aggregating option: Run a traditional mergesort, but attach counters (initialized to 1) to each word; and every time you find yourself comparing two identical words, replace them by a single record with the sum of the counters.