Suppose I have a tree X
a
b c
d e f g
and I want to add a long subtree Y to X
a
b
e
u
so X+Y would look like this.
a
b c
d e f g
u
How would one go about implementing such a tree concatenation?
What you’re describing sounds to me like you’re trying to insert a word into a trie. If that’s what you’re trying to do, you can start at the root of the trie and the beginning of the word and then process each character
x– if there is no edge labeledxfrom the current node, create a new node and add an edge between them; then, in either case, follow the edge labeledxand move to the next character.