https://trusting-wright-17c489.netlify.app/
A demo on Trie data structure
What is a trie?
A trie is a tree-like data structure whose nodes store the letters of an alphabet. By structuring the nodes in a particular way, words and strings can be retrieved from the structure by traversing down a branch path of the tree.
Building the Trie Unlike C++ where we use pointer array for each node, in javaScript we can use regular objects as simplified Hashtables.
TrieNode {
this.value
this.isWord
this.addChild = function(){
this[nextLetter] = new TrieNode()
}
this.a = TrieNode {}
this.b = TrieNode {}
this.c = TrieNode {}
...
}
Searching a word search.js include both linear search and TrieSearch to compare their efficiency. When a user search the result will come from TrieSearch, but both searches will run sequentially to see the advantage of logarithmic time search over linear time search.
Screenshots