AThat gives the best case the worst case's cost. The best case is the row where the number stands first.
BThe search never uses the order, so every number is still looked at.
DOn average it is , about half the row.
pen and paper
5question 5about 8 minutes
Linear search looks for a number that is in the row 34, 81, 12, 57, 6, 95, each place as likely.
Count the looks for the number at each place.
Average them.
Check your average against .
a hint
The number at place costs looks.
a worked answer
The six places cost 1, 2, 3, 4, 5 and 6 looks: 21 in all. Over 6 places that is 3.5. The formula gives 7 over 2, also 3.5.
place
number
looks
1
34
1
2
81
2
3
12
3
4
57
4
5
6
5
6
95
6
in all
21
on average
21 over 6, which is 3.5
Each number of 34, 81, 12, 57, 6, 95 looked for in turn.
Why does a number that is there cost looks on average, each place as likely?10 of 10 shown
1the move: price one place
the line:
Looking for 9: 1 look, found at place 1.
Looking for 41: 2 looks, found at place 2.
Looking for 26: 3 looks, found at place 3.
Looking for 70: 4 looks, found at place 4.
Looking for 13: 5 looks, found at place 5.
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 is the place the number stands at, once in the row. The search looks at places 1 to , then stops. With repeats it stops sooner, as section 3 shows.
2the move: average over the places
the line:
place
looks
chance
looks times its chance
1
1
a fifth
1 fifth
2
2
a fifth
2 fifths
3
3
a fifth
3 fifths
4
4
a fifth
4 fifths
5
5
a fifth
5 fifths
in all
15
5 fifths, which is 1
15 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: is the average looks. By line 1 the places cost 1, 2 and on up to looks. Each place has chance 1 over , so their total is shared by .
guess it, then
3the move: add 1 to n
the line:
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 Fit two staircases of squares together. What shape do they make?
1the move: draw the sum as a staircase
the line:
why it is allowed: Let be the sum of the whole numbers from 1 to . Draw it as a staircase, a column for each number: 1 square, then 2, and so on up to . For 5, columns of 1, 2, 3, 4 and 5 hold 15 squares.
2the move: take two staircases
the line:
why it is allowed: Two staircases hold twice the squares. Doubling both sides of line 1 keeps it true.
3the move: fit them into a rectangle
the line:
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 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 , and the columns fill a rectangle wide and tall.
4the move: halve both sides
the line:
why it is allowed: Halving both sides of line 3 keeps it true and leaves one . For 5, half of 30 is 15.
A shop's till keeps its 40 price codes in a list in no order, each code once. It searches the list with linear search for 300 sales a day, each code as likely. 20 times a day a mistyped code, not on the list, is searched for too.
How many looks does one sale take on average?
About how many looks do the 300 sales take in a day?
How many more do the 20 mistyped codes take?
a hint
A code on the list costs looks on average; one not there costs .
a worked answer
One sale averages 41 over 2, which is 20.5 looks. 300 sales take about 300 times that, 6,150 looks. A mistyped code is not there, so it costs all 40 looks: 20 of them take 800 more.