Skip to content

Instantly share code, notes, and snippets.

@countingtoten
Last active May 25, 2022 15:06
Show Gist options
  • Save countingtoten/dc89b1355ceb32f04be8f9d3787a5c0f to your computer and use it in GitHub Desktop.
Save countingtoten/dc89b1355ceb32f04be8f9d3787a5c0f to your computer and use it in GitHub Desktop.
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