Skip to content

Jump search

finding

Level 2 of 3

Also called Block search.

test yourself

Six questions, four to pick from and two for paper. Each answer stays hidden until you open it.

fresh numbers: the questions a run answers, asked again on new numbers

choose one

question 1

How many looks does jump search take to find 52 in 3, 9, 15, 22, 30, 37, 44, 52, 61, 68, 77, 85?

3915223037445261687785
the answer, and why

the answer is A

Blocks of 3. The ends 15 and 37 are smaller, 61 is not, so the walk starts at place 7. 44, then 52. 5 looks.

  • Looking for 52: 5 looks, found at place 8.

    319215312243053762447452856193681077118512block 1block 2block 3block 4
  • a look, numbered in turn
  • found, ringed
  • looked at, not it
  • ruled out without a look
  • never reached
  • a block passed whole
  • the block looked through
  • a block never reached
Three block ends, then two places of block 3.

if you chose another

  • 52 stands at place 8. That is linear search's count, one look a place.
  • That counts the block ends alone. The walk adds 2.
  • The walk stops at 52, before it reaches 61 again.

question 2

Jump search looks for 38 in 6, 21, 38, 38, 48, 57, 73. At which place does it stop?

6213838485773
the answer, and why

the answer is C

Blocks of 2. Block 1's end, 21, is smaller. Block 2's end, at place 4, is 38, not smaller, so the walk starts at place 3 and finds the first 38 there.

  • Looking for 38: 3 looks, found at place 3.

    61212138333842485576737block 1block 2block 3block 4
  • a look, numbered in turn
  • found, ringed
  • looked at, not it
  • ruled out without a look
  • never reached
  • a block passed whole
  • the block looked through
  • a block never reached
The walk starts at the block's first place, so it stops at the first 38.

if you chose another

  • Place 4 is where 38 is first seen, as block 2's end. The walk then starts at place 3.
  • Place 2 holds 21, smaller, so its block is passed.
  • The search never gets to place 7.

question 3

Which search costs jump search the most looks? Each option is a row, then, after the semicolon, the number wanted.

the answer, and why

the answer is A

68 is the last of the last whole block. 3 block ends, then 3 places, 6 looks.

  • Looking for 75: 5 looks, found at place 10.

    41112193126434543625176086893751045block 1block 2block 3block 4
  • Looking for 68: 6 looks, found at place 9.

    411121931264345436251746085689367510block 1block 2block 3block 4
  • Looking for 80: 4 looks, not there.

    4111219312643454362517608689375104block 1block 2block 3block 4
  • Looking for 4: 2 looks, found at place 1.

    41211219312643454365176086897510block 1block 2block 3block 4
  • a look, numbered in turn
  • found, ringed
  • looked at, not it
  • ruled out without a look
  • never reached
  • a block passed whole
  • the block looked through
  • a block never reached
The four options in order, a to d. Only b looks through a whole block of 3.

if you chose another

  • 75 stands last, but its block holds 1 number. 4 ends and 1 place, 5 looks.
  • 80 is bigger than every block's end, so there is no walk. 4 looks.
  • 4 stands first. 2 looks, the fewest.

question 4

Which is true of jump search's looks, for a number in the row?

the answer, and why

the answer is C

Standing first costs 2 looks, Θ(1)\Theta(1). The last of the last whole block costs ⌊n/m⌋+m\lfloor n / m \rfloor + m, Θ(n)\Theta(\sqrt{n}).

this tests best, worst and average, on the learn page

if you chose another

  • The first look is always at a block's end, so even the first number costs 2.
  • On 2 numbers it can make 3 looks, linear search at most 2.
  • On 10 numbers the last costs 5, but place 9 costs 6.

pen and paper

question 5about 8 minutes

Jump search runs on the 7 numbers 8, 19, 27, 33, 46, 54, 62.

  1. Find the block size and the blocks.
  2. Count the looks for 54 and for 62.
  3. Say why no number of the row costs more.
a hint

The block is the square root of 7, rounded down. A place costs its block's number plus its place in the block.

a worked answer

The root of 7 is about 2.65, so blocks of 2: places 1 and 2, 3 and 4, 5 and 6, and 7 alone. 54 is place 2 of block 3, 3 + 2 = 5 looks. 62 is place 1 of block 4, 4 + 1 = 5 too. The whole blocks are 3, and 3 + 2 = 5 is the most, by the steps below.

placenumberblockplace in the blocklooks
18112
219123
327213
433224
546314
654325
762415
Every place's cost, its block plus its place in the block. The most, 5, is at places 6 and 7.
Which number costs the most looks, and how fast does that most grow?
  1. the move: name the block

    the line:
    m=⌊n⌋m = \lfloor \sqrt{n} \rfloor

    why it is allowed: mm is the block's size, the square root of nn rounded down. The root of 10 is about 3.16, so 10 numbers make blocks of 3.

  2. the move: price one place

    the line:
    place r of block jcosts j+r looks\begin{gathered} \text{place } r \text{ of block } j \\ \text{costs } j + r \text{ looks} \end{gathered}
    looksplace02460246810looksplace02460246810
    • looks for the number at each place, 10 numbers
    Each place's cost on 10 numbers, 2, 3, 4, then 3, 4, 5, then 4, 5, 6, then 5. The top is place 9.

    why it is allowed: To reach block jj, the search looks at jj block ends, the last not smaller. The walk then looks at rr places. In section 3's picture, 70 is place 3 of block 3, so 6 looks, and 84 place 1 of block 4, so 5.

  3. the move: find the costliest

    the line:
    the costliest: the last placeof the last whole block\begin{gathered} \text{the costliest: the last place} \\ \text{of the last whole block} \end{gathered}
    placeblock, jjplace in the block, rrlooks, j+rj + r
    7313 + 1 = 4
    8323 + 2 = 5
    9333 + 3 = 6
    10414 + 1 = 5
    The last four places of section 3's row of 10.

    why it is allowed: The whole blocks are nn over mm, rounded down: 3 for 10. In a whole block, jj is at most that and rr at most mm, both at its last place. A short last block has jj one more but rr one less at least, so it never costs more. On 10 numbers, the short block's one place costs 4 + 1, less than 3 + 3.

  4. the move: count it

    the line:
    W=⌊n/m⌋+mW = \lfloor n / m \rfloor + m

    why it is allowed: WW is the most looks for a number in the row. By line 3, jj is the whole blocks and rr is mm. For 10, 3 + 3 = 6.

  5. the move: at most two blocks past m

    the line:
    W≤2m+2W \le 2m + 2
    9331
    4 times 4 is 16, cut into 3 times 3, two strips of 3 and a corner of 1. Without the corner, 15 is 5 blocks of 3.
    mmthe longest row with blocks of mmwhole blocksm+2m + 2
    1333
    2844
    31555
    42466
    Just under each next square, the whole blocks reach m+2m + 2, and no row has more.

    why it is allowed: Take mm of 3: rows of 9 to 15 numbers. The next square is 4 times 4, 16, and 15 is 5 blocks of 3. In general, the root of nn is under m+1m + 1, as mm is the root rounded down, and rounding down takes off less than 1. So nn is under the next square, m+1m + 1 times m+1m + 1. As the picture shows, that square is mm times mm, two strips of mm and a corner of 1. So nn is at most m+2m + 2 blocks of mm, and the most is the whole blocks, m+2m + 2 at most, plus the walk's mm.

  6. the move: m is at most the root

    the line:
    W≤2n+2W \le 2\sqrt{n} + 2

    why it is allowed: mm is n\sqrt{n} rounded down, so at most n\sqrt{n}. For 10, 2 times 3.16, plus 2, is about 8.3, over 6.

  7. the move: read it as a bound

    the line:
    W∈O(n)W \in O(\sqrt{n})

    why it is allowed: By line 6. From 1 number on, 2 is at most 2 times n\sqrt{n}, so WW is at most 4 times n\sqrt{n}.

  8. the move: at least m whole blocks

    the line:
    W≥m+mW \ge m + m

    why it is allowed: By lines 1 and 4. mm is at most the root of nn, so mm times mm is at most nn, at least mm whole blocks. For 10, 3 times 3 is 9, so 3 + 3.

  9. the move: m is at least 1

    the line:
    W≥m+1W \ge m + 1

    why it is allowed: Every block holds 1 number at least.

  10. the move: rounded down, plus 1, passes the root

    the line:
    W≥nW \ge \sqrt{n}

    why it is allowed: Rounding down takes off less than 1, so m+1m + 1 is more than n\sqrt{n}. For 10, 4 is more than 3.16.

  11. the move: read it as a bound

    the line:
    W∈Ω(n)W \in \Omega(\sqrt{n})

    why it is allowed: By line 10, 1 times n\sqrt{n} at least, from 1 number on.

  12. the move: ceiling and floor together

    the line:
    W∈Θ(n)W \in \Theta(\sqrt{n})

    why it is allowed: Lines 7 and 11 bound WW by the same growth, n\sqrt{n}.

try it with a small nn: at n=10n = 10, line 4 gives W=6W = 6, which you can work out by hand

this tests where the formula comes from, on the learn page

what a full answer includes
  • Blocks of 2, the last of 1 number.
  • 5 looks each, 3 + 2 and 4 + 1.
  • The whole blocks plus mm, 3 + 2, is the most, by the steps below.

question 6about 6 minutes

A tape holds 144 numbers in order, read only from the front. Each place is as likely to hold the number wanted.

  1. About how many looks does jump search average?
  2. At most how many does it make?
  3. If any place could be read at once, at most how many would binary search make?
a hint

144 is 12 times 12, a square row.

a worked answer

Blocks of 12, a square row, so by section 4's question on a square row the average is n+1\sqrt{n} + 1, 13 looks. By the question on the most looks, the most is 144 over 12, plus 12, which is 24. 2 to the power 7 is 128 and to the power 8 is 256, so ⌊log⁡2 n⌋\lfloor \log_2\, n \rfloor is 7 for 144. By the question on binary search, it makes 8 at most. On tape it cannot jump to the middle, so jump search it is.

whathow many
jump search, on average13 looks
jump search, at most24 looks
2 to the power 7, and 8128 and 256
binary search, at most8 looks
144 numbers on tape, and as if any place could be read.
On a square row, mm times mm numbers, what is the average exactly?
  1. the move: price one place

    the line:
    place r of block jcosts j+r looks\begin{gathered} \text{place } r \text{ of block } j \\ \text{costs } j + r \text{ looks} \end{gathered}
    blockplace 1place 2place 3in all
    12349
    234512
    345615
    in all36
    Each cell is its block's number plus its place in the block. 36 looks over 9 places is 4.

    why it is allowed: By line 2 of the question on the most looks. On section 1's 9 numbers, in blocks of 3, every place's cost is in the table.

  2. the move: average every place

    the line:
    S=1m2∑j=1m∑r=1m(j+r)S = \frac{1}{m^2} \sum_{j=1}^{m} \sum_{r=1}^{m} (j + r)

    why it is allowed: SS is the average over the mm times mm places, each as likely. For 3, 36 over 9 is 4.

  3. the move: split the block numbers from the places

    the line:
    S=1m2(m∑j=1mj+m∑r=1mr)S = \frac{1}{m^2} \left( m \sum_{j=1}^{m} j + m \sum_{r=1}^{m} r \right)
    blockblock numbersplaces in the blockin all
    11 + 1 + 1 = 31 + 2 + 3 = 69
    22 + 2 + 2 = 61 + 2 + 3 = 612
    33 + 3 + 3 = 91 + 2 + 3 = 615
    in all181836
    The table of costs split in two. Its block numbers add to 18, its places to 18, and 18 + 18 = 36.

    why it is allowed: Each block's number stands in mm cells of the table, and each place in the block in mm cells too, as the picture splits them. For 3, 3 times 6, plus 3 times 6, is 36, and 36 over 9 is 4.

  4. the move: share out 1 over m squared

    the line:
    S=1m∑j=1mj+1m∑r=1mrS = \frac{1}{m} \sum_{j=1}^{m} j + \frac{1}{m} \sum_{r=1}^{m} r

    why it is allowed: mm over m2m^2 is 1 over mm. For 3, 6 over 3, twice.

  5. the move: use the page on expected cost

    the line:
    S=m+12+m+12S = \frac{m + 1}{2} + \frac{m + 1}{2}
    where does this come from?
    question 1 of the page expected costPick a whole number from 1 to nn, each as likely. What is its expected value?
    1. the move: each value times its chance

      the line:
      E=∑k=1nk×1nE = \sum_{k=1}^{n} k \times \frac{1}{n}
      kktimes its chance
      11 over 5
      22 over 5
      33 over 5
      44 over 5
      55 over 5
      in all15 over 5, which is 3
      For 5, each number times its chance, 1 over 5.

      why it is allowed: The expected value EE adds each number kk times its chance, 1 over nn. Σ\Sigma, read the sum of, adds the term after it for each kk from the value under it to the value over it.

    2. the move: take the chance out in front

      the line:
      E=1n∑k=1nkE = \frac{1}{n} \sum_{k=1}^{n} k

      why it is allowed: Each term is multiplied by 1 over nn, so multiply once, after adding. For 5, 1 over 5 times 15.

    3. the move: use the page on adding up

      the line:
      E=1n×n(n+1)2E = \frac{1}{n} \times \frac{n(n + 1)}{2}
      where does this come from?
      question 1 of the page adding up 1+2+⋯+n1 + 2 + \dots + nFit two staircases of squares together. What shape do they make?
      1. the move: draw the sum as a staircase

        the line:
        S=1+2+⋯+nS = 1 + 2 + \dots + n

        why it is allowed: Let SS be the sum of the whole numbers from 1 to nn. Draw it as a staircase, a column for each number: 1 square, then 2, and so on up to nn. For 5, columns of 1, 2, 3, 4 and 5 hold 15 squares.

      2. the move: take two staircases

        the line:
        2S=2(1+2+⋯+n)2S = 2(1 + 2 + \dots + n)

        why it is allowed: Two staircases hold twice the squares. Doubling both sides of line 1 keeps it true.

      3. the move: fit them into a rectangle

        the line:
        2S=n(n+1)2S = n(n + 1)
        Blue stands, yellow hangs. Two staircases of 1 to 5 squares fill a rectangle 5 wide and 6 tall, 30 squares. So 1 + 2 + 3 + 4 + 5 is 5 times 6, halved, which is 15.

        why it is allowed: Stand one staircase with its tallest column on the left. Hang the other upside down from the top, its tallest column on the right, as in the picture. The first column holds nn standing and 1 hanging. Each column to the right, the standing one loses a square and the hanging one gains one. So every column holds n+1n + 1, and the nn columns fill a rectangle nn wide and n+1n + 1 tall.

      4. the move: halve both sides

        the line:
        S=n(n+1)2S = \frac{n(n + 1)}{2}

        why it is allowed: Halving both sides of line 3 keeps it true and leaves one SS. For 5, half of 30 is 15.

      the whole page: adding up 1+2+⋯+n1 + 2 + \dots + n

      why it is allowed: The whole numbers from 1 to nn add up to nn times one more than nn, halved, as the page on adding up 1 to nn works out. For 5, 5 times 6, halved, is 15.

    4. the move: cancel the n

      the line:
      E=n+12E = \frac{n + 1}{2}

      why it is allowed: nn on top and nn underneath cancel, as nn is not zero. For 5, 6 over 2 is 3.

    5. the move: read it

      the line:
      the middle of1 and n\begin{gathered} \text{the middle of} \\ \text{1 and } n \end{gathered}

      why it is allowed: By line 4, halfway between the smallest number, 1, and the biggest, nn: 3 for 5.

    the whole page: expected cost

    why it is allowed: The box under this line works out the average of a number from 1 to its nn, each as likely, as one more than it, halved. Here, with mm in place of its nn, twice, for the block reached and for the place in it. For 3, 2 and 2.

  6. the move: add

    the line:
    S=m+1S = m + 1

    why it is allowed: Two halves of m+1m + 1. For 3, 4.

  7. the move: m is the root of the row's length

    the line:
    S=n+1S = \sqrt{n} + 1

    why it is allowed: The row holds nn, mm times mm, numbers, so mm is n\sqrt{n}. For 9, 3 + 1 = 4, as section 3's table counts.

try it with a small mm: at m=3m = 3, line 2 gives S=4S = 4, which you can work out by hand

this tests how it compares, on the learn page

what a full answer includes
  • 13, from n+1\sqrt{n} + 1.
  • 24, from 12 + 12.
  • 8, from 7 and 1 more.