diff --git a/source/_posts/数据结构.md b/source/_posts/数据结构.md index 0495f35..8956cbc 100644 --- a/source/_posts/数据结构.md +++ b/source/_posts/数据结构.md @@ -94,4 +94,26 @@ class TreeNode { this.val = val; } } +``` + +## Trie 前缀树或字典树 +Trie树,又叫字典树、前缀树(Prefix Tree)、单词查找树 或 键树,是一种多叉树结构。如下图: +![Tries](/images/trie.png) + +字典树的性质 +1. 根节点(Root)不包含字符,除根节点外的每一个节点都仅包含一个字符; +2. 从根节点到某一节点路径上所经过的字符连接起来,即为该节点对应的字符串; +3. 任意节点的所有子节点所包含的字符都不相同; + +Trie基础method: addWord(), searchWord() +searchPrefix(), 时间复杂度均为word.length + +```java +class TrieNode { + TrieNode[] children; + boolean isWord; + public TrieNode() { + children = new TrieNode[26]; + } +} ``` \ No newline at end of file