Tries Tries are a incredibly useful data structure.
A trie (pronounced "try") is a tree-like data structure used primarily for storing strings where common prefixes are shared. Real-life equivalents of a trie (prefix tree) are seen wherever hierarchical or prefix-based lookup happens. Examples include:
Dictionary or Phonebook Lookup: Words or names are stored alphabetically. As you type more letters, the list of matches narrows—similar to traversing a trie.
Auto-complete or Search Suggestions: When you type in a search bar, suggestions appear based on shared starting letters—powered by tries behind the scenes.
File System Directory Structure: Folders and subfolders represent nested paths, just like nodes in a trie representing parts of strings or paths.
The common form of storing trie data is the form of nodes.
Each node has 3 values.
value = What is the character value for this node?
children = {} A dictionary of all the immediate children for this node
is_last = Which represents if this is the end of the trie