Theory Trie_Ternary
section "Ternary Tries"
theory Trie_Ternary
imports
Tree_Map
Trie_Fun
begin
text ‹An implementation of tries for an arbitrary alphabet ‹'a› where the mapping
from an element of type ‹'a› to the sub-trie is implemented by an (unbalanced) binary search tree.
In principle, other search trees (e.g. red-black trees) work just as well,
with some small adjustments (Exercise!).
This is an implementation of the ``ternary search trees'' by Bentley and Sedgewick
[SODA 1997, Dr. Dobbs 1998]. The name derives from the fact that a node in the BST can now
be drawn to have 3 children, where the middle child is the sub-trie that the node maps
its key to. Hence the name ‹trie3›.
Example from @{url "https://en.wikipedia.org/wiki/Ternary_search_tree#Description"}:
c
/ | \
a u h
| | | \
t. t e. u
/ / | / |
s. p. e. i. s.
Characters with a dot are final.
Thus the tree represents the set of strings "cute","cup","at","as","he","us" and "i".
›