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 coa in cocoa. How many comparisons does it make?

the answer, and why

the answer is B

Place 1: c, o match, c is not a, 3. Place 2: o is not c, 1. Place 3: c, o, a match, 3. That is 7.

if you chose another

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

new numbers

question 2

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

the answer, and why

the answer is C

At each of the 5 places, a, a and a match, then the b differs. That is 4 comparisons at each, 20 in all.

if you chose another

  • abab matches at places 1, 3 and 5, 4 each, but places 2 and 4 cost 1 each, so 14.
  • Only place 1 gets past the first letter, so 4 + 1 + 1 + 1 + 1, which is 8.
  • No first letter ever matches, 1 at each place, so 5.

new numbers