This commit is contained in:
nonstriater
2014-05-16 20:18:24 +08:00
parent da7877336c
commit 7fc950aa3b
+5 -4
View File
@@ -10,7 +10,7 @@
4. 没有键值相等的节点 4. 没有键值相等的节点
typedef int ElemType; ```typedef int ElemType;
typedef struct BiSearchTree{ typedef struct BiSearchTree{
ElemType key; ElemType key;
struct BiSearchTree *lChild; struct BiSearchTree *lChild;
@@ -19,7 +19,7 @@
BiSearchTree *bisearch_tree_insert(BiSearchTree *tree,ElemType node); BiSearchTree *bisearch_tree_insert(BiSearchTree *tree,ElemType node);
int bisearch_tree_delete(BiSearchTree **tree,ElemType node); int bisearch_tree_delete(BiSearchTree **tree,ElemType node);
int bisearch_tree_search(BiSearchTree *tree,ElemType node); int bisearch_tree_search(BiSearchTree *tree,ElemType node);
```
删除节点,需要重建排序树 删除节点,需要重建排序树
@@ -169,6 +169,7 @@ trie,又称为前缀树或字典树,是一种有序树,用于保存关联
子树用数组存储,浪费空间;如果系统中存在大量字符串,且这些字符串基本没有公共前缀,trie树将消耗大量内存 子树用数组存储,浪费空间;如果系统中存在大量字符串,且这些字符串基本没有公共前缀,trie树将消耗大量内存
如果用链表存储,查询时需要遍历链表,查询效率有所降低 如果用链表存储,查询时需要遍历链表,查询效率有所降低
```
define ALPHABET_NUM 26 define ALPHABET_NUM 26
typedef struct Node{ typedef struct Node{
char value; char value;
@@ -179,14 +180,14 @@ int Trie_insert(Trie *trie,char *word); // 插入一个单词
int Trie_search(Trie *trie,char *word);// 查找一个单词 int Trie_search(Trie *trie,char *word);// 查找一个单词
int Trie_delete(Trie *trie,char *word);// 删除一个单词 int Trie_delete(Trie *trie,char *word);// 删除一个单词
```
trie树的增加和删除都比较麻烦,但索引本身就是写少读多,是否考虑添加删除的复杂度上升,依靠具体场景决定 trie树的增加和删除都比较麻烦,但索引本身就是写少读多,是否考虑添加删除的复杂度上升,依靠具体场景决定
DATrie libdatrie 双数组可以减少内存的使用量 DATrie libdatrie 双数组可以减少内存的使用量
double-array trie double-array trie 参考作者的这篇论文 http://linux.thai.net/~thep/datrie/datrie.html
参考作者的这篇论文 http://linux.thai.net/~thep/datrie/datrie.html