doc: add trie section to data structure post
This commit is contained in:
1 parent
d3a6fcb6cc
commit
9595cd77c1
1 file changed
+22
@@ -94,4 +94,26 @@ class TreeNode {
|
||||
this.val = val;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Trie 前缀树或字典树
|
||||
Trie树,又叫字典树、前缀树(Prefix Tree)、单词查找树 或 键树,是一种多叉树结构。如下图:
|
||||

|
||||
|
||||
字典树的性质
|
||||
1. 根节点(Root)不包含字符,除根节点外的每一个节点都仅包含一个字符;
|
||||
2. 从根节点到某一节点路径上所经过的字符连接起来,即为该节点对应的字符串;
|
||||
3. 任意节点的所有子节点所包含的字符都不相同;
|
||||
|
||||
Trie基础method: addWord(), searchWord()
|
||||
searchPrefix(), 时间复杂度均为word.length
|
||||
|
||||
```java
|
||||
class TrieNode {
|
||||
TrieNode[] children;
|
||||
boolean isWord;
|
||||
public TrieNode() {
|
||||
children = new TrieNode[26];
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in new issue
Block a user