add search chapter

This commit is contained in:
nonstriater
2015-11-30 14:05:02 +08:00
parent 4636cb94f3
commit 915b31dd7a
2 changed files with 50 additions and 15 deletions
+10 -7
View File
@@ -39,11 +39,12 @@
###字符串算法
* BF算法
* KMP算法
* BM算法
* 排序
* 查找
* BF算法
* KMP算法
* BM算法
###图的算法
* 图的存储结构和基本操作(建立,遍历,删除节点,添加节点)
@@ -199,7 +200,9 @@ http://ac.jobdu.com/index.php 九度OJ
**局部变量** 尽量短,能表达清楚意思即可,能简写就简写,比如"err" 表示 "error"; "fd" 表示文件描述符 ,循环变量可以使用i,j,k ;结构体成员变量不需要"m_"前缀;全局变量"g_"开头
**常量名/宏定义** 全大写,单词之间"_"分割,如 "MAX_NUMBER_OF_SLAB_CLASSES" ;对于options 宏定义,适当使用前缀 ,比如:
**常量名** 全大写,单词之间"_"分割,如 "MAX_NUMBER_OF_SLAB_CLASSES" ;
**宏定义** 对于options 宏定义,适当使用前缀 ,比如:
```
/* Client classes for client limits, currently used only for
* the max-client-output-buffer limit implementation. */
@@ -210,7 +213,7 @@ http://ac.jobdu.com/index.php 九度OJ
#define CLIENT_TYPE_OBUF_COUNT 3
```
枚举使用前缀:
**枚举** 使用前缀:
```
enum conn_states {
conn_listening, /**< the socket which listens for connections */
+40 -8
View File
@@ -1,30 +1,62 @@
### 查找算法
* 顺序查找
* 二分查找
* 分块查找
* 动态查找
* 哈希表
#### 顺序查找
顺序表查找
顺序表查找。复杂度O(n)
#### 二分查找
有序表中查找我们会使用二分查找。
有序表中查找我们可以使用二分查找。
```
void binary_search()
/*
eg: [1,3,5,6,7,9] k=6
@return 返回元素的索引下表,找不到就返回-1
*/
int binary_search(int *a,int length,int k){
int low = 0;
int high = length-1;
int mid;
while(low<high){
mid = (low+high)/2;
if (a[mid] < k) low = mid+1;
if (a[mid == k]) return mid;
if (a[mid] > k) high = mid-1;
}
return -1;
}
```
#### 分块查找
块内无序,块之间有序;可以先二分查找定位到块,然后再到块中顺序查找
块内无序,块之间有序;可以先二分查找定位到块,然后再到块中顺序查找。
#### 动态查找
>这里之所以叫 动态查找表,是因为表结构是查找的过程中动态生成的
二叉排序树,AVL树,B- ,B+
这里之所以叫 动态查找表,是因为表结构是查找的过程中动态生成的。查找结构通常是二叉排序树,AVL树,B- ,B+等。这部分的内容可以去看『二叉树』章节
#### 哈希表
O(1)
哈希表以复杂度O(1)的成绩位列所有查找算法之首,大量查找的数据结构中都可以看到哈希表的应用。