# 跳跃搜索

跳跃搜索（又称块搜索）是一种用于有序数组的搜索算法，它以固定大小的块向前跳跃遍历数据，然后在可能包含目标元素的块内执行线性搜索。它在计算成本和概念复杂度上都介于[线性搜索](https://www.edgepedia.org/zh/linear-search)与二分搜索之间：最坏情况运行时间为 \( O(\sqrt{n}) \)，优于线性搜索的 \( O(n) \)，但劣于二分搜索的 \( O(\log n) \)。<sup>[1](https://xlinux.nist.gov/dads/HTML/search.html)</sup><sup> • </sup><sup>[2](https://franckc.folk.ntnu.no/idata2302/2023/sequences/searching.html)</sup><sup> • </sup><sup>[3](https://opendsax.cs.vt.edu/ODSA/Books/eu/html/Glossary.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 前提条件 | 仅适用于有序数组；对无序输入会静默失败。<sup>[4](https://www.intraview.ai/explore/TheAlgorithms/Python/tours/jump-search)</sup> |
| 方法 | 以固定大小的块向前跳跃，检查每块的最后一个元素，然后对目标可能所在的块进行线性扫描。<sup>[2](https://franckc.folk.ntnu.no/idata2302/2023/sequences/searching.html)</sup> |
| 最优块大小 | \( k = \sqrt{n} \)，由最小化最坏情况代价 \( n/k + k \) 得到。<sup>[2](https://franckc.folk.ntnu.no/idata2302/2023/sequences/searching.html)</sup> |
| 最坏情况代价 | \( 2\sqrt{n} \) 次比较，即 \( O(\sqrt{n}) \)；当 \( n = 1{,}000{,}000 \) 时约为 2,000 次比较，而二分搜索约为 20 次。<sup>[2](https://franckc.folk.ntnu.no/idata2302/2023/sequences/searching.html)</sup><sup> • </sup><sup>[5](https://ucoruh.github.io/ce205-data-structures/week-6/cen207-week-6/)</sup> |
| 空间 | \( O(1) \)：仅需几个变量分别保存当前索引、上一次跳跃位置和块大小。<sup>[6](https://hasty.dev/blog/searching/jump)</sup> |
| 起源 | Ben Shneiderman，《跳跃搜索：一种快速顺序搜索技术》，《Communications of the ACM》 21(10): 831–834（1978年10月）。<sup>[7](https://dblp.org/rec/journals/cacm/Shneiderman78.html)</sup> |
| 实际地位 | 实测研究将其列为有序数组搜索中执行时间最慢的算法之一，落后于二分搜索和插值搜索。<sup>[8](https://www.ejournal.itn.ac.id/jati/article/view/14360)</sup><sup> • </sup><sup>[9](https://bulletin.feccupit.ro/archive/pdf/2021_2_6.pdf)</sup> |

## 工作原理

该算法利用数组的有序性跳过大部分元素。给定含 \( n \) 个元素的数组和块大小 \( k \)，它检查每块的最后一个元素：若该元素小于目标，则整块可以排除，搜索跳至下一块；否则目标若存在，必位于当前块中，于是从块首开始对该块进行线性搜索。<sup>[2](https://franckc.folk.ntnu.no/idata2302/2023/sequences/searching.html)</sup> 若越过所有块边界仍未找到合适的块，则目标不在数组中。<sup>[2](https://franckc.folk.ntnu.no/idata2302/2023/sequences/searching.html)</sup>

具体而言，在含 16 个元素的数组 (0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610) 中取块大小为 4，搜索 55 时从索引 0 跳到 4，再跳到 8，再跳到 12；由于索引 12 处的元素（89）大于 55，搜索退回索引 8，向前线性扫描找到 55。<sup>[10](https://www.geeksforgeeks.org/dsa/jump-search/)</sup>

## 选择块大小

**平方根是分析的自然结果。** 在最坏情况下，搜索跳过每一个块，然后完整扫描最后一个块，代价为 \( n/k + k \) 次比较。令导数 \( \frac{\partial}{\partial k}(n/k + k) = -n/k^2 + 1 \) 为零，得 \( k = \sqrt{n} \)；代回得 \( 2\sqrt{n} \)，故最坏情况运行时间为 \( O(\sqrt{n}) \)。<sup>[2](https://franckc.folk.ntnu.no/idata2302/2023/sequences/searching.html)</sup> 这一最小化两项成本之和的微积分论证，正是斯坦福大学计算机科学家、《计算机程序设计艺术》作者 Donald E. Knuth 在第三卷《排序与查找》（1973）中介绍块式搜索的方式——将其作为二分搜索的替代方案，仅有一个自由参数，即块大小。<sup>[5](https://ucoruh.github.io/ce205-data-structures/week-6/cen207-week-6/)</sup>

这一权衡有明显的端点：当 \( k = 1 \) 时跳跃搜索退化为线性搜索，当 \( k = n \) 时它只检查一个边界然后扫描全部。<sup>[5](https://ucoruh.github.io/ce205-data-structures/week-6/cen207-week-6/)</sup> 当 \( n = 1{,}000{,}000 \) 时，最优的 \( \sqrt{n} = 1000 \) 次比较对比二分搜索的约 20 次，因此跳跃搜索在渐近意义上慢于二分搜索，但仍远快于线性搜索。<sup>[5](https://ucoruh.github.io/ce205-data-structures/week-6/cen207-week-6/)</sup>

## 历史

马里兰大学计算机科学家 [Ben Shneiderman](https://www.edgepedia.org/zh/ben-shneiderman) 于 1978 年 10 月在《Communications of the ACM》上发表了关于跳跃搜索的系统论述，其动机来自必须使用顺序文件结构而二分搜索不可行的情形。<sup>[7](https://dblp.org/rec/journals/cacm/Shneiderman78.html)</sup><sup> • </sup><sup>[11](https://www.cs.umd.edu/~ben/papers/Shneiderman1978Jump.pdf)</sup> 他的论文指出经典方案的最优跳跃大小为记录数的平方根，并探讨了多级跳跃和可变大小跳跃策略。<sup>[11](https://www.cs.umd.edu/~ben/papers/Shneiderman1978Jump.pdf)</sup> 块搜索的思想本身更早出现在 Knuth 第三卷（1973）中。<sup>[5](https://ucoruh.github.io/ce205-data-structures/week-6/cen207-week-6/)</sup>

Shneiderman 的摘要精确界定了其适用场景：能做二分搜索时很难做得更好，但某些情形更适合跳跃搜索，最常见的是为维持顺序而采用链式结构的排序文件，如高度易变的文件或含变长记录的文件。<sup>[11](https://www.cs.umd.edu/~ben/papers/Shneiderman1978Jump.pdf)</sup>

## 变体

**两级跳跃。** 在定位到的块内再应用一级跳跃可改善渐近复杂度。两级情况下，最优跳跃大小分别为 \( n^{2/3} \) 和 \( n^{1/3} \)，运行时间为 \( O(n^{1/3}) \)。<sup>[12](https://ece.uwaterloo.ca/~dwharder/aads/Algorithms/Searching/Jump_search/)</sup> Shneiderman 对两级固定跳跃搜索的分析同样得出最优大小 \( N^{2/3} \) 和 \( N^{1/3} \)，代价为 \( (3/2)N^{1/3} \)；当级数增长到 \( \log_2 N \) 时，最优跳跃搜索与二分搜索一致。<sup>[11](https://www.cs.umd.edu/~ben/papers/Shneiderman1978Jump.pdf)</sup>

**可变跳跃大小。** 随着搜索接近文件末尾而缩小跳跃步长，比简单跳跃搜索提升约百分之六；最优跳跃大小遵循三角形数函数（1, 3, 6, 10, 15, 21, 28, ...）的逆函数。<sup>[11](https://www.cs.umd.edu/~ben/papers/Shneiderman1978Jump.pdf)</sup> 两级可变方案——第一级使用四角数逆函数——优于其他跳跃搜索，且可与二分搜索竞争；对含 100 条记录的文件，它平均检查约 6.3 个键，而简单跳跃搜索为 10.0 个。<sup>[11](https://www.cs.umd.edu/~ben/papers/Shneiderman1978Jump.pdf)</sup>

**不等代价。** 当一次跳跃的代价与一次顺序步进不同时（如在记录分块的磁带上），最优跳跃大小变为 \( \sqrt{(a/b)N} \)，其中 \( a \) 为跳跃代价，\( b \) 为顺序扫描代价。<sup>[11](https://www.cs.umd.edu/~ben/papers/Shneiderman1978Jump.pdf)</sup>

## 应用

Shneiderman 记录了若干当时的应用。IBM 的 VSAM 在其最低索引层的顺序集上使用跳跃搜索，因为键压缩产生变长键，使二分搜索方案不可行。<sup>[11](https://www.cs.umd.edu/~ben/papers/Shneiderman1978Jump.pdf)</sup> 对于记录分块的磁带搜索，检查每块最后一个键然后扫描正确的块是自然的处理方式。<sup>[11](https://www.cs.umd.edu/~ben/papers/Shneiderman1978Jump.pdf)</sup> 他还列出了索引搜索、列表归并、压缩键搜索和有序消息流扫描等应用。<sup>[11](https://www.cs.umd.edu/~ben/papers/Shneiderman1978Jump.pdf)</sup>

现代描述补充了硬件方面的理由：跳跃搜索适用于向前跳跃代价低而向后跳跃代价高的系统，如顺序访问介质，且其每步算术只需一次加法，而二分搜索需要除法。<sup>[13](https://pkg.go.dev/github.com/thuva4/algorithms/algorithms/searching/jump-search)</sup><sup> • </sup><sup>[5](https://ucoruh.github.io/ce205-data-structures/week-6/cen207-week-6/)</sup>

## 实测性能

基准研究在实际运行时间上将跳跃搜索排在竞争对手之后。2024 年一项印尼研究在有序随机数值数据上比较二分、跳跃、插值和斐波那契搜索，发现跳跃搜索执行时间最长，为 3,233.33 至 3,866.67 纳秒，并得出结论：算法选择应匹配数据分布和规模。<sup>[8](https://www.ejournal.itn.ac.id/jati/article/view/14360)</sup> 2021 年一项在 C++、Java 和 [Python](https://www.edgepedia.org/zh/python-programming-language) 中实现二分、跳跃和插值搜索的研究发现，在 10 万和 50 万数据规模下跳跃搜索执行时间最高（27.25 和 32.5 秒量级的测量值），[插值](https://www.edgepedia.org/zh/interpolation)搜索在三者中执行时间最短，且所用编程语言会影响执行时间。<sup>[9](https://bulletin.feccupit.ro/archive/pdf/2021_2_6.pdf)</sup>

这些结果与理论一致：性能排序为线性搜索 < 跳跃搜索 < 二分搜索，跳跃搜索的优势不在于原始速度，而在于简单、\( O(1) \) 空间、仅向前遍历，以及适用于二分搜索向后跳跃代价高昂的顺序访问场景。<sup>[10](https://www.geeksforgeeks.org/dsa/jump-search/)</sup><sup> • </sup><sup>[6](https://hasty.dev/blog/searching/jump)</sup><sup> • </sup><sup>[13](https://pkg.go.dev/github.com/thuva4/algorithms/algorithms/searching/jump-search)</sup>

## References

1. [Black, Paul E. "search." Dictionary of Algorithms and Data Structures, NIST](https://xlinux.nist.gov/dads/HTML/search.html)
2. [Frigault, Franck. "4. Searching." IDATA 2302, Algorithms and Data Structures, NTNU](https://franckc.folk.ntnu.no/idata2302/2023/sequences/searching.html)
3. ["Glossary." Data Structures & Algorithms, OpenDSA](https://opendsax.cs.vt.edu/ODSA/Books/eu/html/Glossary.html)
4. ["How Jump Search Works." Intraview Explore, TheAlgorithms/Python](https://www.intraview.ai/explore/TheAlgorithms/Python/tours/jump-search)
5. ["Week-6 (Search and Hashing)." CEN207 Data Structures Course Notes](https://ucoruh.github.io/ce205-data-structures/week-6/cen207-week-6/)
6. ["Jump Search – The Block Hopping Algorithm." Hasty.dev](https://hasty.dev/blog/searching/jump)
7. [dblp: Ben Shneiderman, "Jump Searching: A Fast Sequential Search Technique," Commun. ACM 21(10): 831–834 (1978)](https://dblp.org/rec/journals/cacm/Shneiderman78.html)
8. [Ariza, Said Fachri, et al. "Studi Perbandingan Algoritma Pencarian Binary, Jump, Interpolation, dan Fibonacci." JATI 9(4)](https://www.ejournal.itn.ac.id/jati/article/view/14360)
9. [Isola, Esther O., et al. "Comparative Execution Time Analysis for Binary, Jump, and Interpolation Search Algorithms in Object Oriented Languages." University of Pitesti Scientific Bulletin 21(2), 2021](https://bulletin.feccupit.ro/archive/pdf/2021_2_6.pdf)
10. ["Jump Search." GeeksforGeeks](https://www.geeksforgeeks.org/dsa/jump-search/)
11. [Shneiderman, Ben (1978). "Jump Searching: A Fast Sequential Search Technique." Communications of the ACM 21(10): 831–834 (PDF)](https://www.cs.umd.edu/~ben/papers/Shneiderman1978Jump.pdf)
12. [Harder, Douglas Wilhelm. "Jump Search." ECE 250, University of Waterloo](https://ece.uwaterloo.ca/~dwharder/aads/Algorithms/Searching/Jump_search/)
13. ["jump-search." Go Packages, thuva4/algorithms](https://pkg.go.dev/github.com/thuva4/algorithms/algorithms/searching/jump-search)

---
*Initially written Oct 15, 2026 · Edited: Oct 25, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods › Sorting, searching, and selection › Searching in ordered and unordered data

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/jump-search

English original: https://www.edgepedia.org/jump-search
