general
storing endpoints
compressed (saves on memory)
Trie is tree-based data structure.
used to search several strings fast & efficiently
external node is shown as a square, num of external node = num of string
Trie's internal node: max 26 (due to the number of the alphabet).
Trie has num of external node = num of string.
Trie's height is equal to the length of the longest sting.
The number of nodes in Trie is O(n) where n is the number of nodes.
Compressed Tries
# of node in standard trie 22 -> # of node in compressed trie
# of node of compressed trie: O(s) where s is number of string in trie
since # of nodes decrease, space used to store strings are reducing from O(n)->O(s).
trie struct
#define ALPHABET_SIZE 26
node structure with
general
storing endpoints
compressed (saves on memory)
#define ALPHABET_SIZE 26
typedef struct Node *Trie;
typedef struct Node {
char onechar; // current char in key
Trie child[ALPHABET_SIZE];
bool finish; // last char in key?
Item data; // no Item if !finish
} Node;
typedef char *Key; // just lower-case letters