ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Trie.h File Reference

Two digital search trees of strings, beyond the book: More...

#include "ADS/Contract.h"
#include "ADS/Iterators.h"
#include <cstddef>
#include <iterator>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "ADS/dictionary/impl/Trie.tpp"

Go to the source code of this file.

Classes

class  ADS::Trie< V >
 a DICTIONARY of strings on a trie More...
class  ADS::RadixTree< V >
 a DICTIONARY of strings on a compact trie More...

Namespaces

namespace  ADS

Detailed description

Two digital search trees of strings, beyond the book:

  • Trie, the tree of Fredkin whose node at depth \( d \) stands for a prefix of \( d \) characters, the children of a node being indexed by the next character (here by a sorted map); a string is there if the node of its last character is marked. A search, an insertion and a removal take \( O( m \log \sigma ) \) time for a string of \( m \) characters on an alphabet of \( \sigma \), independently of the number of strings, and the strings with a given prefix are those below the node of the prefix, visited in their order;
  • RadixTree, the compact trie (the Patricia of Morrison, on characters rather than on bits), where every chain of nodes with a single child and no mark is merged into one edge labeled by a string, so that it has at most \( 2 n \) nodes for \( n \) strings, however long they are; an insertion splits an edge where the new string departs from it, and a removal merges back a node left with a single child.

Both map each string to a value, i.e., they are a DICTIONARY [see ADT.h] whose keys are strings, with keysWithPrefix() besides. The contracts [see Contract.h]: insert() ensures that the key is there and remove() that it is not; the invariant of RadixTree is that no node but the root has a single child and no mark, and that the labels of the edges out of a node begin with distinct characters. The operations are defined in Trie.tpp.

See also
E. Fredkin, Trie memory, Communications of the ACM 3(9), 490-499, 1960, doi:10.1145/367390.367400
D. R. Morrison, PATRICIA: practical algorithm to retrieve information coded in alphanumeric, Journal of the ACM 15(4), 514-534, 1968, doi:10.1145/321479.321481
D. E. Knuth, The Art of Computer Programming, vol. 3, 2nd ed., Addison-Wesley, 1998, section 6.3
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa