-
Notifications
You must be signed in to change notification settings - Fork 18
/
trie.js
46 lines (36 loc) · 1.22 KB
/
trie.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Trie = function(){
this.characters = {};
};
Trie.prototype.learn = function(word, index){
// This function should add the given word,
// starting from the given index,
// to this Trie.
// It will be recursive. It will tell
// the correct child of this Trie to learn the word
// starting from a later index.
// Consider what the learn function should do
// when it reaches the end of the word?
// A word does not necessarily end at a leaf.
// You must mark nodes which are the ends of words,
// so that the words can be reconstructed later.
};
Trie.prototype.getWords = function(words, currentWord){
// This function will return all the words which are
// contained in this Trie.
// it will use currentWord as a prefix,
// since a Trie doesn't know about its parents.
};
Trie.prototype.find = function(word, index){
// This function will return the node in the trie
// which corresponds to the end of the passed in word.
// Be sure to consider what happens if the word is not in this Trie.
};
Trie.prototype.autoComplete = function(prefix){
// This function will return all completions
// for a given prefix.
// It should use find and getWords.
};
try{
module.exports = Trie
} catch(e){
}