Calculation of optimized algorithmic (Trie) to save time and memory