question 1
Brute force looks for iii in iliiril. How many comparisons does it make?
the answer, and why
the answer is C
At each of the 5 places, it compares from the left until a letter differs or the whole pattern matches: 2 + 1 + 3 + 2 + 1. That is 9.
if you chose another
- That counts only the letters that matched, 1 + 0 + 2 + 1 + 0, not the ones that differed.
- That is the whole pattern at every place, 5 times 3.
- That counts the places, not the comparisons.