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