Skip to content

Linear search

finding

Level 1 of 3

Also called Sequential search.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from linear search's own run on the numbers shown.

choose one

question 1

Linear search looks for 47 in 18, 47, 90, 47, 6. At which place does it stop?

184790476
the answer, and why

the answer is C

It looks at 18, then 47 at place 2, which is the number wanted. It stops there.

  • Looking for 47: 2 looks, found at place 2.

    1811472290347465
  • a look, numbered in turn
  • found, ringed
  • looked at, not it
  • never reached
Two looks. The 47 at place 4 is never reached.

if you chose another

  • That is the second 47. The search stops at the first.
  • Place 1 holds 18, which is not 47.
  • Place 5 is reached only when the number is not there, or stands last. Here it stands at place 2.

new numbers

question 2

How many looks does linear search take to learn that 52 is not in 31, 8, 77, 64, 19, 45, 3?

318776419453
the answer, and why

the answer is B

52 is not there, so every one of the 7 numbers is looked at, once each.

  • Looking for 52: 7 looks, not there.

    31118227733644419554566377
  • a look, numbered in turn
  • looked at, not it
Seven looks, one at each place, and none of them finds 52.

if you chose another

  • One look finds a number only when it stands first.
  • That is the average for a number that is there, (7 + 1) over 2.
  • There is no place 8. The search stops after place 7.

new numbers

question 3

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

the answer, and why

the answer is D

40 stands at place 3, so 3 looks find it. The other three searches each look at all 5 numbers.

  • Looking for 67: 5 looks, found at place 5.

    26118122403313446755
  • Looking for 40: 3 looks, found at place 3.

    261181224033134675
  • Looking for 55: 5 looks, not there.

    26118122403313446755
  • Looking for 26: 5 looks, found at place 5.

    67118122403313442655
  • a look, numbered in turn
  • found, ringed
  • looked at, not it
  • never reached
The four options in order, a to d. Only b stops before the last place, at its third look.

if you chose another

  • 67 stands last, 5 looks.
  • 55 is not there, 5 looks.
  • 26 stands last in this order, 5 looks.

new numbers