Trie (Prefix Tree) in Python

后端 未结 5 1224
情话喂你
情话喂你 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:22

    I don't see anything wrong with your approach. If you're looking for a spike solution, perhaps the action taken in case 4 is actually feasible for the first three cases, IE find the common prefix to k and k' and rebuild the node with that in mind. If it happens that the keys were prefixes of one-another, the resulting trie will still be correct, only the implementation did a bit more work than it really had to. but then again, without any code to look at it's hard to say if this works in your case.

提交回复
热议问题