Study Vault Search notes, aliases and full text
Graph
ConceptDBISAI-written · not yet proofread

Exponential Search

Also Galloping Search

Exponential (galloping) search locates a value x in a sorted array by probing positions with exponentially growing distance (1, 3, 7, …, 2^i − 1) until an element ≥ x is found and then binary searching the last interval, in O(log d) time for d the position of x.

Formula#

For xx at position dd in AA:

time=O(log⁡d)⏟doubling phase+O(log⁡d)⏟binary search in an interval of length<d=O(log⁡d)\text{time} = \underbrace{O(\log d)}_{\text{doubling phase}} + \underbrace{O(\log d)}_{\text{binary search in an interval of length} < d} = O(\log d)

Properties#

Proof
  1. Let j1,…,jkj_1, \ldots, j_k be the probed positions, ji=2i−1j_i = 2^i - 1.
  2. The search did not stop at jk−1j_{k-1}, so jk−1<dj_{k-1} < d, i.e. 2k−1−1<d2^{k-1} - 1 < d, hence 2k−1≤d2^{k-1} \leq d and k≤log⁡2d+1k \leq \log_2 d + 1. The doubling phase takes O(k)=O(log⁡d)O(k) = O(\log d) steps.
  3. Hence jk=2k−1≤2log⁡2d+1−1<2dj_k = 2^k - 1 \leq 2^{\log_2 d + 1} - 1 < 2d. The binary search halves its interval (of length <2d< 2d) in every step, so it takes O(log⁡(2d))=O(log⁡2+log⁡d)=O(log⁡d)O(\log(2d)) = O(\log 2 + \log d) = O(\log d) steps.
  4. Both phases together: O(log⁡d)O(\log d). ■\blacksquare
Proof
  1. After kk jumps the probed position is 0+1+2+…+2k−1=2k−10 + 1 + 2 + \ldots + 2^{k-1} = 2^k - 1. The search stops there, so 2k−1≥i2^k - 1 \geq i, i.e. k≥log⁡2(i+1)k \geq \log_2(i+1).
  2. It did not stop one jump earlier, at position 2k−1−12^{k-1} - 1, so 2k−1−1<i2^{k-1} - 1 < i, i.e. k−1<log⁡2(i+1)k - 1 < \log_2(i+1).
  3. Hence kk is the smallest integer ≥log⁡2(i+1)\geq \log_2(i+1): k=⌈log⁡2(i+1)⌉k = \lceil \log_2(i+1) \rceil. ■\blacksquare
  • Doubling variant. DBIS Exam WS2223 (not published) (Task 1.1) probes the positions 0,1,2,4,8,…0, 1, 2, 4, 8, \dots (i = max(2 * i, 1)) instead. For jj the smallest index with A[j]=xA[j] = x this returns an index ii with j≤i≤2jj \leq i \leq 2j in O(log⁡(1+j))O(\log(1 + j)) time; the 1+1 + handles j=0j = 0.
  • Use in list intersection. Searching each element of the shorter list in the longer one with galloping search, each search starting where the previous one stopped, gives the O(k⋅log⁡(1+n/k))O(k \cdot \log(1 + n/k)) intersection algorithm (List Intersection > 3. Galloping (Exponential) Search Intersection).
  • Compared with plain binary search over the whole array (O(log⁡n)O(\log n)), the cost depends only on the distance dd to the target, not on the array length nn; this pays off when the target is near the start.

Example#

A=[2,3,5,8,13,21,34,55,89,144]A = [2, 3, 5, 8, 13, 21, 34, 55, 89, 144], x=34x = 34 (position d=6d = 6):

  • Doubling phase: probe A[0]=2A[0] = 2, A[1]=3A[1] = 3, A[3]=8A[3] = 8 (all <34< 34), then A[7]=55≥34A[7] = 55 \geq 34: stop after k=3k = 3 jumps (⌈log⁡2(7+1)⌉=3\lceil \log_2(7 + 1) \rceil = 3 with i=7i = 7 the first position with A[i]>34A[i] > 34).
  • Binary search in positions 4..74..7: A[5]=21<34A[5] = 21 < 34, then A[6]=34A[6] = 34: found.

Sources#

  • DBIS Exam WS1920 (not published) Task 1.3 (number of jumps), DBIS Exam WS2122 (not published) Task 1.4 (O(log⁡d)O(\log d) proof), DBIS Exam WS2223 (not published) Task 1.1 (implementation)
  • DBIS Exam WS1819 (not published) Task 1.2 (galloping search intersection)
  • Not lectured in WS 25/26; DBIS_VL01 > Query Processing covers only the linear-time zipper.

Search

Type In
↑ ↓ move ↵ open ⇥ next section Ctrl↵ results page Prefix # to search text only