1.2 KiB
Tries - Prefix Trees(syntax trees in disguise)
We can build grammers from symbols where symbols follow a set of rules to build on each other. Kinda like linguistic sytax trees but, exactly the same. Individual syntaxes are combined to build grammers combine to build phrases, etc. etc.
Instead of symbols we use prefixes as our terminology, to build words. Terminally sequenced symbols are denoted by a leaf flag.
Nodes
Nodes in tries are a bit special in that they carry some metadata. * Leaf flags: just because a node is set as a leaf, it doesn't mean the node itself is a leaf in the trie
Deletion
We don't actually remove things for trivial cases. Instead we turn off the leaf flag in the end target node
if we have /bathe/ and /bathes/ as valid phrases and wanted to remaove /bathe/ from our language * All we have to do is set the /e/ to off as a valid leaf.
If instead we wanted to remove /bathes/ instead we would go to /s/ and then set it to off like before. * The problem now is that /s/ is hanging and it doesn't have any children so we can remove it entirely * If a toggled off node has children it means that it necessarily is part of a valid prefix so it can not be removed