二进制搜索问题? [英] Binary Search Problems?

查看:187
本文介绍了二进制搜索问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/504335/what-are-the-pitfalls-in-implementing-binary-search">What在执行二进制搜索的陷阱?

我仔细阅读了二进制搜索的维基百科页面和克努特下面无意中发现了一个报价:

I was perusing the wikipedia page for Binary Search and stumbled on a quote by Knuth below:

虽然二进制搜索的基本思想是比较直观,细节更是出奇地刁钻

"Although the basic idea of binary search is comparatively straightforward, the details can be surprisingly tricky"

我记得实施多项二进制搜索我的计算机科学课程的一部分,但不记得它是非常棘手的。但是,这篇文章指出,90%的受访专业人士不能几个小时后得到一个工作。我想承担这一不因为这些是可怕的程序员,但有附带案件天真实现不占。

I recall implementing several Binary Searches as part of my Computer Science curriculum, but don't remember it being terribly tricky. However, this article states that 90% of surveyed professionals can't get one working after several hours. I'd like to assume this not because these are terrible programmers, but that there are fringe cases that naive implementations don't account for.

什么是细节,克努特是指呢?什么是常见的问题要注意,如果实现的二进制搜索算法?

What are the details that Knuth is referring too? What are the common gotchas to be aware of if implementing a Binary Search algorithm?

请注意,我读了一篇文章布洛赫有关的编程珠玑的错误(int型的中点溢出)。还有什么?

Note I read that article by Bloch about the Programming Pearls bug(overflow of an int for midpoint). Is there anything else?

推荐答案

作为一个在Java世界在我的日常工作​​,我记得的这个。我是pretty的惊讶,当我第一次读到它,这可能是的东西唐纳德在谈论的。

Being in Java world in my day job, I remember this. I was pretty surprised when I first read it so this may be one of the things Donald was talking about.

这篇关于二进制搜索问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆