Last active
May 25, 2022 15:06
-
-
Save countingtoten/dc89b1355ceb32f04be8f9d3787a5c0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
/* | |
A trie (pronounced try) is a tree datastructure that links nodes by a common character. | |
It is also known as a prefix tree because all children of a node will have a common prefix. | |
It is like an efficient set of strings. | |
Example: trie containing the words car, care, cart, cer, are | |
/ \ | |
c a | |
/ \ \ | |
a e r | |
| | | | |
r r e | |
/ \ | |
e t | |
*/ | |
type Trie struct { | |
// Your code here. | |
} | |
func NewTrie(words []string) *Trie { | |
// Your code here. | |
} | |
func (t *Trie) Has(word string) bool { | |
// Your code here. | |
} | |
func main() { | |
words := []string{"progress", "license", "promise", "promote"} | |
t := NewTrie(words) | |
fmt.Println(t.Has("progress")) // true | |
fmt.Println(t.Has("propogate")) // false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment