Good algorithm and data structure for looking up words with missing letters?

前端 未结 20 1892
不思量自难忘°
不思量自难忘° 2020-12-07 07:12

so I need to write an efficient algorithm for looking up words with missing letters in a dictionary and I want the set of possible words.

For example, if I have th??

20条回答
  •  一整个雨季
    2020-12-07 07:44

    Directed Acyclic Word Graph would be perfect data structure for this problem. It combines efficiency of a trie (trie can be seen as a special case of DAWG), but is much more space efficient. Typical DAWG will take fraction of size that plain text file with words would take.

    Enumerating words that meet specific conditions is simple and the same as in trie - you have to traverse graph in depth-first fashion.

提交回复
热议问题