4 ms·
Note that to save memory, instead of using every character in the word, you may want to cap the depth of your trie to the first N chars. The words with shared
by psadri 5y ago
Note that to save memory, instead of using every character in the word, you may want to cap the depth of your trie to the first N chars. The words with shared prefixes are kept in an array at the leafs. During lookups, you’d scan the leaf array to find matches. You’d be trading space (lots of nested objects) vs speed (negligible for scanning small arrays).
- ufo 5y agoAnother way to save space is to use a directed acyclic graph. Specially if there are common suffixes that show up all the time.