Block Search
   HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, a jump search or block search refers to a
search algorithm In computer science, a search algorithm is an algorithm designed to solve a search problem. Search algorithms work to retrieve information stored within particular data structure, or calculated in the search space of a problem domain, with eith ...
for ordered lists. It works by first checking all items ''L''''km'', where k \in \mathbb and ''m'' is the block size, until an item is found that is larger than the
search key Searching or search may refer to: Computing technology * Search algorithm, including keyword search ** :Search algorithms * Search and optimization for problem solving in artificial intelligence * Search engine technology, software for findi ...
. To find the exact position of the search key in the list a
linear search In computer science, a linear search or sequential search is a method for finding an element within a list. It sequentially checks each element of the list until a match is found or the whole list has been searched. A linear search runs in at ...
is performed on the sublist ''L'' ''k''-1)''m'', ''km''/sub>. The optimal value of ''m'' is , where ''n'' is the length of the list ''L''. Because both steps of the
algorithm In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algorithms are used as specificat ...
look at, at most, items the algorithm runs in O() time. This is better than a
linear search In computer science, a linear search or sequential search is a method for finding an element within a list. It sequentially checks each element of the list until a match is found or the whole list has been searched. A linear search runs in at ...
, but worse than a
binary search 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 m ...
. The advantage over the latter is that a jump search only needs to jump backwards once, while a binary can jump backwards up to log ''n'' times. This can be important if jumping backwards takes significantly more time than jumping forward. The algorithm can be modified by performing multiple levels of jump search on the sublists, before finally performing the
linear search In computer science, a linear search or sequential search is a method for finding an element within a list. It sequentially checks each element of the list until a match is found or the whole list has been searched. A linear search runs in at ...
. For a ''k''-level jump search the optimum block size ''m''''l'' for the ''l'' th level (counting from 1) is ''n''(k-l)/k. The modified algorithm will perform ''k'' backward jumps and runs in O(''kn''1/(''k''+1)) time.


Implementation

algorithm JumpSearch is input: An ordered list ''L'', its length ''n'' and a search key ''s''. output: The position of ''s'' in ''L'', or nothing if ''s'' is not in ''L''. ''a'' ← 0 ''b'' ← ⌊√''n''⌋ while ''L''min(''b'',''n'')-1 < ''s'' do ''a'' ← ''b'' ''b'' ← ''b'' + ⌊√''n''⌋ if ''a'' ≥ ''n'' then return nothing while ''L''''a'' < ''s'' do ''a'' ← ''a'' + 1 if ''a'' = min(''b'', ''n'') return nothing if ''L''''a'' = ''s'' then return ''a'' else return nothing


See also

*
Skip list In computer science, a skip list (or skiplist) is a probabilistic data structure that allows \mathcal(\log n) average complexity for search as well as \mathcal(\log n) average complexity for insertion within an ordered sequence of n elements. ...
*
Interpolation search Interpolation search is an algorithm for searching for a key in an array that has been ordered by numerical values assigned to the keys (''key values''). It was first described by W. W. Peterson in 1957. Interpolation search resembles the method ...
*
Linear search In computer science, a linear search or sequential search is a method for finding an element within a list. It sequentially checks each element of the list until a match is found or the whole list has been searched. A linear search runs in at ...
- runs in O(''n'') time, only looks forward *
Binary search 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 m ...
- runs in O(log ''n'') time, looks both forward and backward


References

* {{DADS, jump search, jumpsearch *
Ben Shneiderman Ben Shneiderman (born August 21, 1947) is an American computer scientist, a Distinguished University Professor in the University of Maryland Department of Computer Science, which is part of the University of Maryland College of Computer, Mathe ...
, ''Jump Searching: A Fast Sequential Search Technique'', CACM, 21(10):831-834, October 1978. Search algorithms