It is a bit unclear what the purpose of data
is; do you want to associate some information with each stored string? Basically, adding a new string would mean that you start at the root of the trie, then read s
character-wise and traverse the arcs of the trie correspondingly as long as this is possible. If all characters of s
are consumed in this process, you are done; if there is some suffix of s
left, you have to add new nodes and arcs to accomodate for the suffix. In either case, you arrive at a node where you can store data
if this is desired.