简体   繁体   中英

How to use Trie to do partial autocomplete

Given a large list of words (say 1 million). Using Trie, we could easily implement prefix match. But how can I implement partial match.

For example we have a list of words {"abc", "def", "lunch", "diner"....}, how I can get lunch when searching "unc"?

Is Trie still a good data structure to use in this case? What are the possible ways to implement it efficiently?

The most common structure used for this sort of application is a Suffix Tree This is really a version of a Trie that allows all the suffixes for a string to be stored efficiently in a single structure. There are other options but this is a good balance between efficiency and simplicity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM