简体   繁体   English

如何从字符数组中创建 trie 中单词的组合/排列?

[英]How can I create a combination/permutation of words in a trie from a character array?

I have a trie that contains multiple words in it.我有一个包含多个单词的 trie。 I am attempting to create a permutation/combination of all possible words that can be found in the dictionary from an array of characters without repeats of letters in the char array.我正在尝试从字符数组中创建可以在字典中找到的所有可能单词的排列/组合,而字符数组中没有重复的字母。 I have tried to research ideas/starting point but all the possible solutions I have found are allowing repeats, which is not what I want.我试图研究想法/起点,但我发现的所有可能的解决方案都允许重复,这不是我想要的。

For example:例如:

Suppose I have the words {tiptoe, top, tuple, put, pups, pop, putt } in the trie and I have the char array that contains: [t, i, p, u, l, o, e, s].假设我在 trie 中有单词 {tiptoe, top, tuple, put, pups, pop, putt },并且我有一个包含 [t, i, p, u, l, o, e, s] 的 char 数组。

The output should be: output 应该是:

  • top最佳
  • tuple元组
  • put

Can someone please help me out with starting this algorithm?有人可以帮我启动这个算法吗?

  1. iterate char array 1.a pick first char 1.b iterate word array 1.bA mark all chars in all words(only first match in a word) in word array if picked char is match with those chars.迭代字符数组 1.a 选择第一个字符 1.b 迭代单词数组 1.bA 如果选择的字符与这些字符匹配,则在单词数组中标记所有单词中的所有字符(仅第一个匹配单词)。
  2. Those words having all chars are marked are the output标记了所有字符的那些单词是 output

Example first iteration:第一次迭代示例:

char from char array = t;
chars marked in word array : {t`iptoe, t`op, t`uple, put`, pups, pop, put`t } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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