摘要: 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 8 int Insert_search(int *a, int key, int n) 9 {10 int pos, low, high;11 low = 0,high = n - 1;12 while(low <= high){13 pos = ((key - a[low]) * (high - low )) / (a[high] - a[low]) + low;14 if(a[pos] < key){15 ... 阅读全文
posted @ 2013-09-26 13:02 cpoint 阅读(1356) 评论(0) 推荐(0) 编辑
摘要: 斐波那契查找的核心是: 1)当key=a[mid]时,查找成功; 2)当keya[mid]时,新的查找范围是第mid+1个到第high个,此时范围个数为F[k-2] - 1个,即数组右边的长度,所以要在[F[k - 2] - 1]范围内查找。代码如下: 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 #define MAXSIZE 20 8 9 void fibonacci(int *f) //构建斐波那契序列10 {11 f[0] = 1;12 f[1] = 1;13 for(int i ... 阅读全文
posted @ 2013-09-26 11:39 cpoint 阅读(2859) 评论(0) 推荐(0) 编辑
摘要: 在计算机科学中,折半搜索,也称二分查找算法、二分搜索,是一种在有序数组中查找某一特定元素的搜索算法。搜素过程从数组的中间元素开始,如果中间元素正好是要查找的元素,则搜素过程结束;如果某一特定元素大于或者小于中间元素,则在数组大于或小于中间元素的那一半中查找,而且跟开始一样从中间元素开始比较。如果在某一步骤数组为空,则代表找不到。这种搜索算法每一次比较都使搜索范围缩小一半。复杂度分析时间复杂度折半搜索每次把搜索区域减少一半,时间复杂度为。(n代表集合中元素的个数)空间复杂度 。虽以递归形式定义,但是尾递归,可改写为循环。C代码如下: 1 #include 2 #include 3 #includ 阅读全文
posted @ 2013-09-26 01:40 cpoint 阅读(1199) 评论(0) 推荐(0) 编辑
浏览次数:travelocity promotion codes