Tries
A tree is a powerful data structure that is used in various scenarios. One of them is related to processing strings, such as for autocomplete and spellchecker features that you certainly know from many systems. If you want to implement it in your application, you can benefit from another tree-based data structure, namely a trie. It is used to store strings and to perform prefix-based searching.
A trie is a tree with one root node, where each node represents a string and each edge indicates a character. A trie node contains references to the next nodes as an array with 26 elements, representing 26 chars from the alphabet (from a to z). When you go from the root to each node, you receive a string, which is either a saved word or its substring.
Why exactly 26 elements?
Here, we use 26 elements representing 26 chars because it is the exact number of basic characters between a
and z
in the alphabet, without any special characters existing in various languages. Of course,...