| 49 | |
| 50 | //It returns true if there exists a word which starts with the provided word |
| 51 | public boolean startsWith(String word){ |
| 52 | TrieNode curr= root; |
| 53 | |
| 54 | for(int i=0; i< word.length(); i++){ |
| 55 | char ch= word.charAt(i); |
| 56 | |
| 57 | if(curr.children[ch - 'a'] == null) //We pick a char from the string and keep moving to the children |
| 58 | return false; |
| 59 | |
| 60 | curr= curr.children[ch -'a']; |
| 61 | } |
| 62 | return true; //It the we have completely traversed the string and the above false condition is encountered that means there is a word in trie that starts with the provided string |
| 63 | } |
| 64 | |
| 65 | //This function is used to delete the provided word from our Trie |
| 66 | public void delete(String word) { |