Trie (Prefix Tree) in Python

后端 未结 5 1220
情话喂你
情话喂你 2020-12-12 23:14

I don\'t know if this is the place to ask about algorithms. But let\'s see if I get any answers ... :)

If anything is unclear I\'m very happy to clarify things.

5条回答
  •  青春惊慌失措
    2020-12-12 23:23

    I have a question regarding your implementation. What is the level of granularity that you decide to split your strings on to make the prefix tree. You could split stack as either s,t,a,c,k or st,ta,ac,ck and many other ngrams of it. Most prefix tree implementations take into account an alphabet for the language, based on this alphabet, you do the splitting.

    If you were building a prefix tree implementation for python then your alphabets would be things like def, : , if , else... etc

    Choosing the right alphabet makes a huge difference in building efficient prefix trees. As for your answers, you could look for PERL packages on CPAN which do longest common substring computation using trie's. You may have some luck there as most of their implementation is pretty robust.

提交回复
热议问题