资源 · 指南或文章
Binary Search
简短定义有序数组上的二分查找,这是许多折半类面试题的出发点。
审核日期
打开原站: Binary Search (在新标签页中打开原网站)练习这个主题打开练习面试官,并带上一道关于 二分查找 的题目。
添加到路线图
把这个资源放进你正在跟进的路线图。它会作为你自己的补充资源显示;路线图的步骤不会改变,也不计入你已记录的步骤。
来源内容语言:英语
Read this in other languages: Português brasileiro. Español. In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the array; if they are unequal, the half in which the target cannot lie is eliminated and the search continues on the remaining half until it is successful. If the search ends with the remaining half being empty, the target is not in the array. Time Complexity: O(log(n)) - since we split search area by two for every next iteration.
PrepKit 概览
本概览由 PrepKit 编辑根据源代码仓库撰写并审核,并非资源本身的文字。
- 适合人群
- 来源未说明适用级别
- 形式
- 参考资料
涵盖内容
- 每次与中间元素比较如何排除剩余范围的一半。
- 剩余范围为空时意味着什么:目标不存在。
- 给出时间复杂度为 O(log(n))。
使用建议
这是 PrepKit 的学习建议,并非来源的说法。
分别写出迭代和递归版本,然后测试空数组、单元素数组以及目标不存在的情况。
范围与局限
非常简短:没有讨论差一错误,没有下界或上界变体,也没有练习题。链接到维基百科和 YouTube。另有葡萄牙文和西班牙文版本。
获取方式与形式
GitHub 上的免费英文 README(trekhleb/javascript-algorithms,MIT)。
PrepKit 于 2026年10月2日 审核。 资源来源提交: 85293e3e2b88
本概览的依据
- src/algorithms/search/binary-search/README.md
相关备考资料
这些是 PrepKit 的学习建议,不代表雇主推荐,也不预测面试题目。
- Binary Search
经审阅的题目与资源关联。
- Find Minimum In Rotated Sorted Array
经审阅的题目与资源关联。
- First Bad Version
经审阅的题目与资源关联。
收录此条目的页面
订阅 PrepKit 通讯
可选。使用 PrepKit 并不需要订阅。