二分法查找是基于有序_改进的二分法查找

—60— 改进的二分法查找 王海涛,朱 洪 (复旦大学计算机科学与工程系,上海 200433) 摘 要:当前有很多的查找算法,其中在对有序数列的查找算法中二分法查找(binary search)是最常用的。利用二分法,在含有n个元素的有序数列中查找一个元素的最大比较次数为 log 1n +⎢⎥ ⎣⎦。在很多情况中,在查找之前有序数列分布的很多信息为已知,比如说如果知道了有序数列中每相邻两个元素之差的最大值的一个上界,就可以有比二分法更加有效的查找算法。文章给出了一个称之为改进的二分法查找算法。改进的二分法查找性能明显优于二分法查找,受数列分布的影响,其最坏情况下查找一个元素的最大比较次数在 1 和 log 1n +⎢⎥ ⎣⎦之间, 明显优于二分查找的 log 1n +⎢⎥ ⎣⎦。在实际应用中利用改进的二分法可以极大地提高查找效率。 关键词:查找;二分法;有序数列;算法 Modified Binary Search WANG Haitao, ZHU Hong (Department of Computer Science and Engineering, Fudan University, Shanghai 200433) 【Abstract】Consider the problem of determining whether a given elementx is in array. To solve the search problem, there are many algorithms. And binary search is the most common search algorithm if the array is sorted. The number of comparisons performed by binary search on a sorted array of size n is at most log 1n +⎢⎥ ⎣⎦. The time cost of binary search reaches the lower bound of the search problem. But in many circumstances, some information about the array before search is known. If the upper bound of the maximum difference between any adjacent elements in the array is known, one can design a preferable algorithm. It is referred as modified binary search. In the worst case, the maximum number of comparisons performed by modified binary search is between 1 and log 1n +⎢⎥ ⎣⎦, obviously better than binary search. 【Key words】Search; Binary search; Sorted array; Algorithm 计 算 机 工 程 Computer Engineering 第32卷 第10期 Vol.32 № 10 2006 年 5 月May 2006 ·软件技术与数据库· 文章编号:1000—3428(2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值