Possible Duplicate:
Where do I find a standard Trie based map implementation in Java?
I want to use Trie in Java, is there an implementation I can use ? (I tried looking for one but I didn't found it).
A tree is a general structure of recursive nodes. There are many types of trees. Popular ones are binary tree and balanced tree. A Trie is a kind of tree, known by many names including prefix tree, digital search tree, and retrieval tree (hence the name 'trie').
Often this value is a unique identifier or pointer that gets you to some data related to the key (e.g., primary key of a record in a DBMS). Like a map, a trie can also be used to store only keys with no associated values.
Also, we can easily print all the words in the dictionary in alphabetic order with a trie. Therefore, if we want a full-text lookup application, the hash table is better as it has a faster lookup speed. However, if we want to return all the words that match a prefix, the trie is our solution.
A trie is essentially two linked lists. A (vertical) link to it's left-most child and a (horizontal) link to it's right sibling.
There is no trie data structure in the core Java libraries.
This may be because tries are usually designed to store character strings, while Java data structures are more general, usually holding any Object
(defining equality and a hash operation), though they are sometimes limited to Comparable
objects (defining an order). There's no common abstraction for "a sequence of symbols," although CharSequence
is suitable for character strings, and I suppose you could do something with Iterable
for other types of symbols.
Here's another point to consider: when trying to implement a conventional trie in Java, you are quickly confronted with the fact that Java supports Unicode. To have any sort of space efficiency, you have to restrict the strings in your trie to some subset of symbols, or abandon the conventional approach of storing child nodes in an array indexed by symbol. This might be another reason why tries are not considered general-purpose enough for inclusion in the core library, and something to watch out for if you implement your own or use a third-party library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With