Tries are tree data structures that store a dynamic set of strings, supporting efficient search, insertion, and deletion of strings in time proportional to the length of the strings. Standard tries use more space (O(n) where n is total string size) while compressed tries reduce space to O(m) where m is number of strings by merging chains of single-child nodes. Common applications include autocomplete dictionaries and compressing lookup tables for sparse data.
3. TRIE
•DIGITAL TREE / RADIX TREE / PREFIX TREE.
•The name trie comes from its use for
retrieval
• you can pronounce it as TRY or TREE both
are acceptable
4. Why tries ?
•We have seen that preprocessing the pattern
speeds up pattern matching queries .
•If the text is large, immutable and searched for
often ,we may want to preprocess the text instead
of the pattern in order to perform pattern
matching queries in time proportional to the
pattern length.
5. Standard Tries
The standard trie for a set of strings S is an
ordered tree such that:
1.each node but the root is labeled with a
character
2.the children of a node are alphabetically
ordered
3.the paths from the external nodes to the
root yield the strings of S
Example: standard trie for the set of strings
S = { bear, bell, bid, bull,
buy, sell, stock, stop }
6.
7.
8.
9.
10. •A standard trie uses O(n) space and supports
searches, insertions and deletions in time
O(dm), where:
n total size of the strings in S
m size of the string parameter of the
operation
d size of the alphabet
11. Application
•A common application of a trie is storing
a predictive text or autocomplete dictionary,
such as found on a mobile telephone. Such
applications take advantage of a trie's ability
to quickly search for, insert, and delete
entries
12. Compressed Tries:
• A compressed trie is like a standard trie but makes sure that each trie
had a degree of at least 2. Single child nodes are compressed into a
single edge.
• It is obtained from standard trie by compressing chains of “redundant”
nodes
14. Compact Representation Of Compressed
Tries:
• Compact representation of a compressed trie for an array of strings:
• Stores at the nodes ranges of indices instead of substrings
• Uses O(s) space, where s is the number of strings in the array
• Serves as an auxiliary index structure
17. Compression TRIES Algorithm:
• Replace:
• a redundant chain or edges (v0,v1), (v1,v2), ..., (vk−1,vk)
• by one edge:
• (v0 ,vk)
• Replace:
• the label vk
• by the label:
• v v2....vk
18. • Each internal node in a compressed tire has at least two children
and each external is associated with a string. The compression
reduces the total space for the trie from O(m) where m is the sum
of the the lengths of strings in S to O(n) where n is the number of
strings in S.
19. Applications:
• Tries are usually static i.e. insertion and deletion are disabled.
• Therefore they are used in compression of the already available
data.
• This application is typically used for compressing lookup tables
when the total set of stored keys is very sparse within their
representation space.
• It is also typically used in the implementation of the various
fast lookup tables needed to retrieve Unicode character
properties (for example to represent case mapping tables, or
lookup tables containing the combination of base and combining
characters needed to support Unicode normalization