Working with Graphs & Trees
What type of tree structure is specialized for string operations?
class Trie {
constructor() {
this.root = {};
this.endSymbol = '*';
}
insert(word) {
let current = this.root;
for (let char of word) {
if (!(char in current)) {
current[char] = {};
}
current = current[char];
}
current[this.endSymbol] = true;
}
}