Two common ways to store children in a trie node: Array (fixed alphabet): children: array of 26 (for lowercase letters) # Access: children[ord(c) - ord('a')] Hash map (flexible): children: map from char to TrieNode # Access: children.get(c) Trade-offs: - Array: access, wastes space for sparse tries - Map: Slight overhead, memory-efficient for large alphabets For lowercase English letters, array is typically faster.
For Unicode or variable alphabets, map is necessary. Choose based on your alphabet size and sparsity. Time: . Space: .