跳到主要内容

资源 · 指南或文章

Jump Search

有序数组上的跳跃查找:每隔 m 个元素探测一次,然后在正确的块内线性扫描。

审核日期

打开原站: Jump Search (在新标签页中打开原网站)

添加到路线图

把这个资源放进你正在跟进的路线图。它会作为你自己的补充资源显示;路线图的步骤不会改变,也不计入你已记录的步骤。

来源内容语言:英语

Like Binary Search, Jump Search (or Block Search) is a searching algorithm for sorted arrays. The basic idea is to check fewer elements (than linear search) by jumping ahead by fixed steps or skipping some elements in place of searching all elements. For example, suppose we have an array arr[] of size n and block (to be jumped) of size m. Then we search at the indexes arr[0], arr[m], arr[2 * m], ..., arr[k * m] and so on. Once we find the interval arr[k * m] x arr[(k+1) * m], we perform a linear search operation from the index k * m to find the element x. What is the optimal block size to be skipped? In the worst case, we have to do n/m jumps and if the last checked value is greater than the element to be searched for, we perform m - 1 comparisons more for linear search. Therefore the total number of comparisons in the worst case will be ((n/m) + m - 1). The value of the function ((n/m) + m - 1) will be minimum when m = √n. Therefore, the best step size is m = √n.

PrepKit 概览

本概览由 PrepKit 编辑根据源代码仓库撰写并审核,并非资源本身的文字。

适合人群
来源未说明适用级别
形式
参考资料

涵盖内容

  • 下标模式 arr[0]、arr[m]、arr[2m],以及最后的线性扫描。
  • 根据最坏情况下的比较次数推导出最佳块大小 m = sqrt(n)。
  • 给出时间复杂度为 O(sqrt(n))。

使用建议

这是 PrepKit 的学习建议,并非来源的说法。

在纸上重现块大小的推导,然后实现它,并统计 n = 100、m = 10 时的比较次数。

范围与局限

内容简短,没有代码讲解或练习;参考资料是 GeeksForGeeks 和维基百科。

获取方式与形式

英文 README,可在 GitHub 上的 trekhleb/javascript-algorithms(MIT 许可)中免费阅读。

PrepKit 于 2026年10月2日 审核。 资源来源提交: 85293e3e2b88

本概览的依据
  • src/algorithms/search/jump-search/README.md

收录此条目的页面

订阅 PrepKit 通讯

可选。使用 PrepKit 并不需要订阅。

我们如何处理你的邮箱