A Double Array Trie with Tail implementation in Java, with the following features:
-
finds words that start with the given prefix;
-
finds all words occurring in a given pattern from left to right;
e.g: given the pattern "wverticall" the words found will be "vertical", "call" and "all";
-
finds all the valid words from the permutation of the given letters;
e.g: given the letters "a e r d" the words found will be "dare","dear","are","rad","red","read","ear" and "era";
-
finds all the words that fit in the given string expression according to the wildcards' position;
e.g: given the expression "s??ce", where the symbol ? is the wildcard, the words found will be "slice", "space", "since", ecc ...
Useful for finding anagrams and words.
It is an improvement of the standard Trie, based on a double array trie and a tail.
Thanks to the double array, it has better performance and memory occupation.
Credits:
- Aoe, J. An Efficient Digital Search Algorithm by Using a Double-Array Structure. IEEE Transactions on Software Engineering. Vol. 15, 9 (Sep 1989). pp. 1066-1077.
- https://linux.thai.net/~thep/datrie/
- https://github.com/digitalstain/DoubleArrayTrie
Create and populate the DATrie
DoubleArrayTrie trie = new DoubleArrayTrie();
for(String word : myDictionary) {
trie.insert(word);