Skip to content

Brute-force search

words

Level 1 of 3

Also called Naive string 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 brute-force search's own run on the numbers shown.

choose one

question 1

Brute force looks for mn in mnnmmmmm. How many comparisons does it make?

the answer, and why

the answer is A

At each of the 7 places, it compares from the left until a letter differs or the whole pattern matches: 2 + 1 + 1 + 2 + 2 + 2 + 2. That is 12.

if you chose another

  • That counts only the letters that matched, 2 + 0 + 0 + 1 + 1 + 1 + 1, not the ones that differed.
  • That is the whole pattern at every place, 7 times 2.
  • That counts the places, not the comparisons.

new numbersthe test page's numbers

question 2

Each text has eight letters and each pattern four. Which makes brute force compare the most?

the answer, and why

the answer is A

At each of the 5 places, it compares from the left until a letter differs or the whole pattern matches. eeleelle, eele takes 13 comparisons, the most of the four.

if you chose another

  • That takes 5 comparisons, fewer than 13.
  • That takes 9 comparisons, fewer than 13.
  • That takes 8 comparisons, fewer than 13.

new numbersthe test page's numbers