Skip to content

Linear search

finding

Level 1 of 3

Also called Sequential search.

how it works

The idea in a few sentences and a picture, then one search step by step.

Linear search looks at the numbers of a row one at a time, from the left. Each look asks one question: is this the number wanted? Yes, and it stops, found. No, and it moves to the next. Past the last number, it is not there. The row may be in any order, since the search never uses the order. Its plain name in Sebastian Bourges' books is reading down, a list read from the top (volume one, chapter 1); its formal names are linear search and sequential search.

  • Looking for 42: 1 look, found at place 1.

    421172313184565236127498
  • Looking for 56: 5 looks, found at place 5.

    4211722313318445655236127498
  • Looking for 30: 8 looks, not there.

    4211722313318445655236612774988
  • a look, numbered in turn
  • found, ringed
  • looked at, not it
  • never reached
One row, three searches. Each yellow triangle is a look, numbered in turn. Where a search stops decides its cost, its number of looks.
Halfway along: 6 moments of its 12 steps, the steps between them left for the watch page
  1. step 1 of 12

    427311856231249

    There are 8 numbers in a row, and their order does not matter. Look for 56, one number at a time from the left.

    what it remembers to know where it is
    looking for
    56
    looking at place
    not yet

    Where it says not yet, nothing is held there at that moment.

    watch from here

  2. step 2 of 12

    427311856231249

    Look at place 1. It holds 42. Is that 56?

    what it remembers to know where it is
    looking for
    56
    looking at place
    1

    watch from here

  3. step 3 of 12

    427311856231249

    No, 42 is not 56. Rule it out and move to the next.

    what it remembers to know where it is
    looking for
    56
    looking at place
    1

    watch from here

  4. step 4 of 12

    427311856231249

    Look at place 2. It holds 7. Is that 56?

    what it remembers to know where it is
    looking for
    56
    looking at place
    2

    watch from here

  5. step 10 of 12

    427311856231249

    Look at place 5. It holds 56. Is that 56?

    what it remembers to know where it is
    looking for
    56
    looking at place
    5

    watch from here

  6. step 11 of 12

    427311856231249

    Yes. 56 is at place 5, so it is found.

    what it remembers to know where it is
    looking for
    56
    looking at place
    5

    watch from here

the steps, in plain words
  1. start at the first numberPython line 7
  2. look at the numberPython line 8
  3. if it is the number wanted, it is foundPython line 9
  4. otherwise rule it out and move to the nextPython line 7
  5. past the last number, it is not in the rowPython line 10
the same in Python

The steps in plain words are what to learn. Python is a programming language, and the code below does the same steps, for those who code. Python numbers the places in a list from 0, not 1: the first number is numbers[0], the second numbers[1], and so on.

def linear_search(row, target):
    """Look at each number of the row, from the left, until one is target.

    Returns its place, counted from 0 as Python counts places, or None
    when target is not in the row. The row may be in any order.
    """
    for place, number in enumerate(row):  # from the first number on
        if number == target:  # one look: is this the number wanted?
            return place  # found, at the first place it stands
    return None  # past the last number: it is not in the row

how it scales

How the looks grow, from ten numbers to ten million.

The marks across and up go 10, 100, 1,000 and on, equally spaced. Not there climbs one mark up for each mark across: ten times the numbers, ten times the looks. The average climbs about the same, and standing first stays flat at 1 look.

looks, ten times more at each mark up

slope 1102104106101102103104105106107slope 1101102103104105106107101102103104105106107slope 1101102103104105106107101102103104105106107

nn, how many numbers are in the row, ten times more at each mark to the right

  • it is not theresolid where measured by running it; dashed where its formula carries it on to ten millionslope 1: ten times n, 10 times the work
  • it is there once, each place as likelysolid where measured by running it; dashed where its formula carries it on to ten million
  • the number wanted stands firstsolid where measured by running it; dashed where its formula carries it on to ten million
what a dearest row costs, at a billion looks a second
nnlookstime
1,0001,000about 1 microsecond
100,000100,000about 100 microseconds
10,000,00010,000,000about 10 milliseconds

The looks are the same on any computer. The times are not: a real computer may be faster or slower than a billion a second.

make these counts yourself

Copy this script and run it with Python 3.12 or later. It counts the same steps as the plot. Where a count depends on a random shuffle, yours will differ a little.

"""Count the looks of linear search yourself, as this page's plot does.

Run it with Python 3.12 or later. For each size n it shuffles 1 to n and
prints the looks when the number wanted stands first, the cheapest; when it
is not in the row, the dearest; and the average when it is there, each
place as likely, worked out by trying every place. That average is exact;
the plot's points average 20 places spread over the row, about 2 per cent
under it. The counts are the same on any computer; only the time differs.
"""
import random


class Counted:
    """A number that counts every look: each time it is compared."""

    looks = 0

    def __init__(self, value):
        self.value = value

    def __eq__(self, other):
        Counted.looks += 1
        return self.value == other.value


def linear_search(row, target):
    """Look at each number of the row, from the left, until one is target.

    Returns its place, counted from 0 as Python counts places, or None
    when target is not in the row. The row may be in any order.
    """
    for place, number in enumerate(row):  # from the first number on
        if number == target:  # one look: is this the number wanted?
            return place  # found, at the first place it stands
    return None  # past the last number: it is not in the row


def count(row, target):
    """How many looks linear search makes looking for target in row."""
    Counted.looks = 0
    linear_search([Counted(x) for x in row], Counted(target))
    return Counted.looks


if __name__ == "__main__":
    random.seed(1)
    print(f"{'n':>6} {'first':>6} {'not there':>10} {'average':>9}")
    for n in [10, 100, 1000]:
        row = list(range(1, n + 1))
        random.shuffle(row)  # any order will do
        every = sum(count(row, number) for number in row) / n
        print(f"{n:>6} {count(row, row[0]):>6} {count(row, 0):>10} {every:>9}")

best, worst and average

One search costs from 1 look up to a look at every number, depending on where the number stands.

A case is one kind of input, the thing the method is given, such as a row back to front, whatever its length. A bound says how fast that case's cost grows as the input gets longer.

The counts are in the grid. A count is often the sum of pieces that grow at different speeds, and on long inputs the fastest-growing piece swamps the rest. For example, a count of half of n times n, less half of n: at 2,000 items, 2,000,000 less 1,000. So how a cost grows is what tells one method from another, and the bounds keep just that.

what each case costs, and how fast that cost grows; section 4 works out every formula in it
bestthe number wanted stands firstaverageit is there once, each place as likelyworstit is not there
looks1, the first look finds itn+12\frac{n + 1}{2}, about half the rownn, a look at every number
how the looks grow in each case
tight, Θ\ThetaΘ(1)\Theta(1)Θ(n)\Theta(n)Θ(n)\Theta(n)
ceiling, OOO(1)O(1)O(n)O(n)O(n)O(n)
floor, Ω\OmegaΩ(1)\Omega(1)Ω(n)\Omega(n)Ω(n)\Omega(n)

extra memory: one extra box, the place reached; the number wanted comes with the input

Extra memory is the room it needs on top of the input itself, while it runs.

  • Looking for 15: 1 look, found at place 1.

    151162283474335
  • Looking for 33: 5 looks, found at place 5.

    1511622283347443355
  • Looking for 20: 5 looks, not there.

    1511622283347443355
  • Looking for 47: 3 looks, found at place 3.

    15116222473384475
  • a look, numbered in turn
  • found, ringed
  • looked at, not it
  • never reached
Standing first, 1 look. Standing last, 5, and not there, 5 too. Both cost 5, the most. The page takes not there as the worst case: it costs every look in any order. The fourth row is changed to hold 47 twice: the search stops at the first.
looksnumbers in the row0510152005101520looksnumbers in the row0510152005101520
  • not there, nn
  • there on average, n+12\frac{n + 1}{2}
  • standing first, 1
Double the row and the looks double when not there, and on long rows almost double on average. Standing first stays at 1.
numbersstanding firstthere on averagenot there
1111
211.52
3123
412.54
5135
1015.510
100150.5100
1,0001500.51,000
Each the search's own count, the average over every place, each tried once. Ten times the row gives exactly ten times the looks when not there, and on long rows about ten times on average.

where the formula comes from

Each count above, worked out in small steps. Every step names the line it uses.

Why does a number standing first cost 1 look, however long the row?
  1. the move: watch the first look

    the line:
    the first look finds it\text{the first look finds it}
    • Looking for 27: 1 look, found at place 1.

      271164253904
    • a look, numbered in turn
    • found, ringed
    • never reached
    27 stands first, so the first look finds it. Places 2 to 4 are never reached.

    why it is allowed: The first look is at place 1, and the number there is the one wanted, so the search stops.

  2. the move: count it

    the line:
    B=1B = 1

    why it is allowed: BB is the looks when the number wanted stands first. By line 1, one, for 4 numbers or 4 million.

  3. the move: a ceiling

    the line:
    B≤1B \le 1

    why it is allowed: By line 2. An equals gives a ceiling and a floor at once; OO needs the ceiling, and Ω\Omega the floor.

  4. the move: read it as a bound

    the line:
    B∈O(1)B \in O(1)

    why it is allowed: By line 3, a fixed number of looks, whatever nn is.

  5. the move: a floor

    the line:
    B≥1B \ge 1

    why it is allowed: By line 2 again.

  6. the move: read it as a bound

    the line:
    B∈Ω(1)B \in \Omega(1)

    why it is allowed: By line 5.

  7. the move: ceiling and floor together

    the line:
    B∈Θ(1)B \in \Theta(1)

    why it is allowed: Lines 4 and 6 bound BB by the same growth, 1, which is to say none.

try it with a small nn: at n=4n = 4, line 2 gives B=1B = 1, which you can work out by hand

Why does a number that is not there cost nn looks?
  1. the move: follow the search

    the line:
    not there: every placeis looked at, once\begin{gathered} \text{not there: every place} \\ \text{is looked at, once} \end{gathered}
    • Looking for 50: 4 looks, not there.

      271164225339044
    • a look, numbered in turn
    • looked at, not it
    50 is not there, so every place is looked at, 4 looks for 4 numbers.

    why it is allowed: Each look says no and moves on, so the search reaches the end. It never looks at a place twice.

  2. the move: a look a place

    the line:
    W=1+1+⋯+1W = 1 + 1 + \dots + 1

    why it is allowed: WW is the looks for a number not there. By line 1, one for each of the nn places.

  3. the move: count the ones

    the line:
    W=nW = n

    why it is allowed: Line 2 has nn ones. For 4 numbers, 4.

  4. the move: a ceiling

    the line:
    W≤nW \le n

    why it is allowed: By line 3.

  5. the move: read it as a bound

    the line:
    W∈O(n)W \in O(n)

    why it is allowed: By line 4, 1 times nn at most.

  6. the move: a floor

    the line:
    W≥nW \ge n

    why it is allowed: By line 3 again.

  7. the move: read it as a bound

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

    why it is allowed: By line 6.

  8. the move: ceiling and floor together

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

    why it is allowed: Lines 5 and 7 bound WW by the same growth, nn.

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

Why does a number that is there cost n+12\frac{n + 1}{2} looks on average, each place as likely?
  1. the move: price one place

    the line:
    the number at place kcosts k looks\begin{gathered} \text{the number at place } k \\ \text{costs } k \text{ looks} \end{gathered}
    • Looking for 9: 1 look, found at place 1.

      911412263704135
    • Looking for 41: 2 looks, found at place 2.

      9114122263704135
    • Looking for 26: 3 looks, found at place 3.

      91141222633704135
    • Looking for 70: 4 looks, found at place 4.

      911412226337044135
    • Looking for 13: 5 looks, found at place 5.

      9114122263370441355
    • a look, numbered in turn
    • found, ringed
    • looked at, not it
    • never reached
    Each of the 5 numbers looked for in turn. The number at place 3 costs 3 looks.

    why it is allowed: Here kk is the place the number stands at, once in the row. The search looks at places 1 to kk, then stops. With repeats it stops sooner, as section 3 shows.

  2. the move: average over the places

    the line:
    A=(1+2+⋯+n)×1nA = (1 + 2 + \dots + n) \times \frac{1}{n}
    placelookschancelooks times its chance
    11a fifth1 fifth
    22a fifth2 fifths
    33a fifth3 fifths
    44a fifth4 fifths
    55a fifth5 fifths
    in all155 fifths, which is 115 fifths, which is 3
    The 5 numbers of line 1, each as likely. The chances add up to 1, and the last column to 3, the average.

    why it is allowed: AA is the average looks. By line 1 the places cost 1, 2 and on up to nn looks. Each place has chance 1 over nn, so their total is shared by nn.

  3. the move: add 1 to n

    the line:
    A=n(n+1)2×1nA = \frac{n(n + 1)}{2} \times \frac{1}{n}
    The looks for places 1 to 5 stand as columns of 1 to 5. The same, hung upside down, fill a rectangle 5 wide and 6 tall, 30 squares. Half is 15, the looks in all.
    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 box under this line adds 1 to nn with two staircases, as the picture does for 5. For 5, 5 times 6 over 2 is 15.

  4. the move: share by n

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

    why it is allowed: Sharing by nn takes away the nn that multiplies n+1n + 1. For 5, 15 over 5 is 3, the table's average.

  5. the move: a floor

    the line:
    A≥n2A \ge \frac{n}{2}

    why it is allowed: In line 4, n+1n + 1 is more than nn.

  6. the move: read it as a bound

    the line:
    A∈Ω(n)A \in \Omega(n)

    why it is allowed: By line 5, at least half of nn.

  7. the move: a ceiling

    the line:
    A≤n+n2A \le \frac{n + n}{2}

    why it is allowed: In line 4, 1 is at most nn.

  8. the move: halve 2n

    the line:
    A≤nA \le n

    why it is allowed: n+nn + n over 2 is nn.

  9. the move: read it as a bound

    the line:
    A∈O(n)A \in O(n)

    why it is allowed: By line 8.

  10. the move: ceiling and floor together

    the line:
    A∈Θ(n)A \in \Theta(n)

    why it is allowed: Lines 6 and 9 bound AA by the same growth, nn. On average, about half the row.

try it on small inputs: over the number at each of 5 places, 15 looks in all, the average is A=3A = 3

At most how many looks does binary search make on a row of nn numbers in order? Section 7 compares it with linear search.
  1. the move: what one look keeps

    the line:
    each look keeps at mosthalf, rounded down\begin{gathered} \text{each look keeps at most} \\ \text{half, rounded down} \end{gathered}
    two middleslooking for 666142735485963713 beforedropped4 afterkeptthe look, in neither sidethe other middle
    The first look, at 35. 66 must be after it, so binary search keeps those 4 and drops the rest.

    why it is allowed: Binary search needs the row in order. It looks at the middle of what is left and keeps the side the number must be on. The look itself is in neither side, and of two middles it takes the first. So of these 8, the side after holds 4, half rounded down, and the side before 3.

  2. the move: count the halvings

    the line:
    H=halvings to one number+1 look at it\begin{gathered} H = \text{halvings to one number} \\ + 1 \text{ look at it} \end{gathered}
    numberlog× 2+ 11021428372.81
    7 lies between 4 and 8, so its log lies between 2 and 3 and rounds down to 2. That is 3 looks for 7 numbers.
    rounding down84213 halvings
    8 halved, rounding down, goes 4, 2 and 1. Three halvings, then one more look reads the last number, so 4 looks.

    why it is allowed: HH is the most looks. 66 keeps exactly half at each look: 8 numbers, then 4, 2 and 1, three halvings, and a fourth look reads the last. Fewer numbers never cost more looks, as the box under line 3 shows. So the most is the halvings, plus 1.

  3. the move: use the page on halving

    the line:
    H=⌊log⁡2 n⌋+1H = \lfloor \log_2\, n \rfloor + 1
    where does this come from?
    question 3 of the page halving and logarithmsBinary search on a row of nn numbers. At most how many looks?
    1. the move: what one look keeps

      the line:
      at most half, rounded down,of what is left\begin{gathered} \text{at most half, rounded down,} \\ \text{of what is left} \end{gathered}
      two middleslooking for 7510203040506070803 beforedropped4 afterkeptthe look, in neither sidethe other middle
      8 numbers have two middles; the table's 7 have one.
      lookstill to searchhalf, rounded downthe middlekept
      110, 20, 30, 40, 50, 60, 703.5 to 34050, 60, 70
      250, 60, 701.5 to 16070
      3700.5 to 070none
      75 is above all 7 numbers, so each look keeps the side after.

      why it is allowed: This site's binary search looks at the middle of what is left, the first of two middles, and keeps the side the wanted number must be on. From 8 it keeps 3 before or 4 after: the side after holds half, rounded down, the side before no more.

    2. the move: fewer numbers, no more looks

      the line:
      keeping a smaller part nevercosts more looks\begin{gathered} \text{keeping a smaller part never} \\ \text{costs more looks} \end{gathered}
      after lookkeeping the bigger sidekeeping the smaller side
      01010
      154
      221
      31none
      4none
      Two searches on 10 numbers. Keeping the bigger side runs out after 4 looks, the smaller after 3.

      why it is allowed: Let A always keep the bigger side, and S be any search on the same row. While S holds no more than A, it keeps at most half of its part, rounded down, so no more than A keeps. In the table, S keeps 4 to A's 5, then 1 to 2. So S runs out no later.

    3. the move: a number that keeps the bigger side

      the line:
      a number above them allkeeps the bigger side\begin{gathered} \text{a number above them all} \\ \text{keeps the bigger side} \end{gathered}

      why it is allowed: Each middle is too small, so each look keeps the side after it. That is A of line 2.

    4. the move: count that search's looks

      the line:
      ⌊log⁡2 n⌋ looks leaveone number, one morelook leaves none\begin{gathered} \lfloor \log_2\, n \rfloor \text{ looks leave} \\ \text{one number, one more} \\ \text{look leaves none} \end{gathered}

      why it is allowed: Each look halves, rounding down, so question 2 of the page halving and logarithms counts the looks to one number. 1 number takes no halving, log 0. For 7, 7 leaves 3, 3 leaves 1, and look 3 leaves none.

    5. the move: the most looks

      the line:
      B=⌊log⁡2 n⌋+1B = \lfloor \log_2\, n \rfloor + 1

      why it is allowed: Let BB be the most looks, which lines 2 to 4 count. For 7 numbers, the search for 75 takes 3, as the table at line 1 shows.

    6. the move: read it

      the line:
      one more look thanthe log rounded down\begin{gathered} \text{one more look than} \\ \text{the log rounded down} \end{gathered}

      why it is allowed: For 7 numbers, 2 and 1 more. For 16, 4 and 1 more.

    the whole page: halving and logarithms

    why it is allowed: The box under this line works out the most looks as ⌊log⁡2 n⌋+1\lfloor \log_2\, n \rfloor + 1. 8 halves to 4, 2 and 1: three halvings, as 2 times 2 times 2 is 8, so the log of 8 is 3, and 4 looks. 7 goes to 3 and 1: two halvings, 3 looks. 2 to the power 0 is 1, so the log of 1 is 0: 1 look.

try it with a small nn: at n=8n = 8, line 2 gives H=4H = 4, which you can work out by hand

count it yourself

Count every look on the row 64, 15, 38, 9, 71, looking for 40, which is not there.

64, 15, 38, 9, 71; 40, every step written down
stepwhat happenslooks
1There are 5 numbers in a row, and their order does not matter. Look for 40, one number at a time from the left.0
2Look at place 1. It holds 64. Is that 40?1
3No, 64 is not 40. Rule it out and move to the next.1
4Look at place 2. It holds 15. Is that 40?2
5No, 15 is not 40. Rule it out and move to the next.2
6Look at place 3. It holds 38. Is that 40?3
7No, 38 is not 40. Rule it out and move to the next.3
8Look at place 4. It holds 9. Is that 40?4
9No, 9 is not 40. Rule it out and move to the next.4
10Look at place 5. It holds 71. Is that 40?5
11No, 71 is not 40. Rule it out and move to the next.5
12All 5 numbers are ruled out, so 40 is not in the row.5
13Done after 5 looks.5

In all, 5 looks. The formula from section 4, W=nW = n, gives W=5W = 5 at n=5n = 5: the same.

where you meet it

Most programming languages hand you linear search ready made.

  • Python's in and index

    The table below asks Python for 23 and 30 in the row 7, 23, 31, 23, 56, 12, kept as a list, Python's row of items. in and index search it as this page does, from index 0. For 30, index stops with an error, ValueError.

    source: the Python tutorial, More on Lists (opens in a new tab), list.index; Common Sequence Operations (opens in a new tab); CPython's Objects/listobject.c, list_index_impl and list_contains

  • JavaScript's indexOf and includes

    An array is JavaScript's row of items. Asked for 30, indexOf searches it the same way and gives minus 1, its word for not there. includes walks it the same way for whole numbers, but answers true or false.

    source: the ECMAScript specification, ECMA-262 (opens in a new tab), Array.prototype.indexOf and Array.prototype.includes

  • a database with no index

    A database index is a guide to a column, as a book's index is to its pages. A database with no index on a column reads every record to find a value, which PostgreSQL calls a sequential scan: this page's not there.

    source: the PostgreSQL documentation, Using EXPLAIN (opens in a new tab) and Indexes, Introduction (opens in a new tab)

askedanswerwhy
row.index(23)1place 2 on this page, the first 23
23 in rowTruefound at the second look
row.index(30)ValueErrorevery item looked at, none equal
linear_search(row, 30)Nonethis page's Python, for not there
indexOf(30), in JavaScriptminus 1its word for not there
Asking for 23 and 30 in the row 7, 23, 31, 23, 56, 12, kept as a list called row.

what is used instead

A row kept in order and searched often is searched with binary search instead, each look halving what is left. For many searches, a dictionary finds a key without looking at every one. Sebastian Bourges' books, Algorithmic Thinking Without the Jargon, weigh this in volume one, chapter 1. "On twenty items the difference is about ten looks against four, and simplicity is worth six looks". On 20 numbers this page's average is 21 over 2, which is 10.5. And sorting a row only to search it once does not pay: "you have spent far more than you saved".

how it compares

Linear search beside three searches that need the row in order.

wayhow it looksneeds the row in ordermost looksmost on 12 numbersreach for it when
linear searchone number at a time, from the leftnonn12the row is short, or in no order and searched once
binary searchthe middle of what is left, keeping one sideyes⌊log⁡2 n⌋+1\lfloor \log_2\, n \rfloor + 1, by the last question of section 44the row is in order and searched many times
jump searcha block at a time, then through the blockyesat most twice the root of the numbers, plus 2, by its own page7the row is in order but can only be read from the front, as on tape
interpolation searchguesses the place from the number's sizeyesone fewer than the numbers from 2 numbers on, by its own page1 on 8, 16 and on to 96; 10 on 1 to 11 then 99the row is long, in order, and close to equal steps
The most looks over searches for every number from 1 to 99, on 12 numbers in order, by each search's own run. The last column's first two rows follow Sebastian Bourges' books (volume one, chapter 1).
102104106101102103104105106107101102103104105106107101102103104105106107
  • linear search, not there, nn
  • linear search, there on average, n+12\frac{n + 1}{2}
  • binary search at most, ⌊log⁡2 n⌋+1\lfloor \log_2\, n \rfloor + 1
Linear search climbs one mark for each mark across; binary search barely rises. At ten million numbers, ten million looks against 24. Jump and interpolation search are not drawn.

race them on one row of your own