Trie or Prefix Tree - All Operations
What is trie? Trie is a search tree that is used to store and search strings in space and time-efficient way. How String is stored in a trie? A trie node consists of Hashmap of <Character, address of next Trie Node> and a boolean flag endOfWord In any trie node, we can store non-repetitive multiple characters.(Remember we use hashmap. Right?) For any given string, it's each character is stored in different trie nodes. After storing all the characters of a string in different trie nodes, we make a new trie node and mark its endOfWord flag as true, indicating the end of that particular string. Practical Uses of Trie Spelling checker Autocomplete feature Code (Please read comments in code for the explanation of each step) import java.util.*; // A node of trie class TrieNode{ // A hashmap to store the characters and address of its next trie node HashMap<Character,TrieNode> chars; ...