|
3179 | 3179 | - Runtime: **O(|*Patterns*|)**: the total length of all Texts
|
3180 | 3180 | - Space Complexity: (Edges # = **O(|*Patterns*|)**):
|
3181 | 3181 | - It takes lot of space: E.g, for human genome, the total length |*Text*| is 10^12 => Space?
|
| 3182 | + - It could be implemented with a **dictionary of dictionaries**: |
| 3183 | + - The key of the external dictionary is the node ID (integer) |
| 3184 | + - The internal dictionary contains all the trie edges outgoing from the corresponding node |
| 3185 | + - The internal dictionary keys are the letters on those edges |
| 3186 | + - The internal dictionary values are the node IDs to which these edges lead |
3182 | 3187 | - E.g., the string texts below could be stored in a Trie:
|
3183 | 3188 | - aba, aa, baa
|
3184 |
| - Root |
3185 |
| - / \ |
3186 |
| - a b |
3187 |
| - / \ \ |
3188 |
| - b a a |
3189 |
| - / |
3190 |
| - a |
| 3189 | + 0 Trie = { 0: { a:1, b:5 } |
| 3190 | + a/ \b 1: { b:2, a:4} |
| 3191 | + 1 5 2: { a:3 } |
| 3192 | + b/ \a \a 3: { } |
| 3193 | + 2 4 6 4: { } |
| 3194 | + a/ 5: { a:6 } |
| 3195 | + 3 5: { } |
| 3196 | + } |
3191 | 3197 | - Multiple Pattern Matching:
|
3192 | 3198 | - For simplicity, we assume that no pattern is a substring of another pattern
|
3193 | 3199 | - TrieMatching(Text, Trie):
|
|
3210 | 3216 | - Runtime of brute force approach: **O(|*Text*| * |*Patterns*|)**
|
3211 | 3217 | - Related Problems:
|
3212 | 3218 | - [Construct a Trie from a Collection of Patterns](https://github.com/hamidgasmi/training.computerscience.algorithms-datastructures/issues/154)
|
| 3219 | + - [Multiple Pattern Matching](https://github.com/hamidgasmi/training.computerscience.algorithms-datastructures/issues/155) |
| 3220 | + - [Generalized Multiple Pattern Matching](https://github.com/hamidgasmi/training.computerscience.algorithms-datastructures/issues/156) |
| 3221 | + - [Implement an autocomplete feature](): |
| 3222 | + - Tries are a common way of storing a dictionary of words and are used, e.g., for implementing an autocomplete feature in text editors |
| 3223 | + - E.g., Code editors, and web search engines like Google or Yandex |
3213 | 3224 | - For more details:
|
3214 | 3225 | - UC San Diego Course:[Tries](https://github.com/hamidgasmi/training.computerscience.algorithms-datastructures/blob/master/5-string-processing-and-pattern-matching-algorithms/1-suffix-trees/01_suffix_trees.pdf)
|
3215 | 3226 |
|
|
0 commit comments