BThat is how a count growing as times times grows.
DThe places and the pattern both grow, so the count does too.
pen and paper
5question 5about 6 minutes
A tape holds the letters baabaab. Search it for aab by brute force, numbering places from 1.
For each place, how many comparisons?
Where does aab stand?
How many comparisons in all?
a hint
At each place, compare from the left until a letter differs or all 3 match.
a worked answer
5 places. Place 1, b is not a: 1. Place 2, a, a and b match: 3. Place 3, a matches, then b is not a: 2. Place 4, b is not a: 1. Place 5, a, a and b match: 3. aab stands at places 2 and 5, and the comparisons are 1 + 3 + 2 + 1 + 3, which is 10.
place
letters above
comparisons
1
baa
1
2
aab
3, a match
3
aba
2
4
baa
1
5
aab
3, a match
aab under each place of baabaab. It matches at places 2 and 5.
A text holds 1,001 letters, all a. The pattern has half as many, rounded up.
How many letters has the pattern, and at how many places is it tried?
How many comparisons if it is all b?
How many if it is a's ending in b?
a hint
Questions 1 and 2 of the learn page's section 4 count each.
a worked answer
Half of 1,001 rounded up is 501 letters. Places: 1,001 - 501 + 1, which is 501. All b: one comparison at each place, 501. a's ending in b: all 501 letters at each of the 501 places, 501 times 501, which is 251,001.
Question 2: how many comparisons, , on a text of a's and a pattern of a's ending in b, half as long, rounded up?8 of 8 shown
1the move: a place's most
the line:
why it is allowed: At a place the pattern's letters are compared from the left, one each, until one differs. It has letters, so at most .
2the move: every letter but the last matches
the line:
place
letters above
against
comparisons
1
aaa
aab
3
2
aaa
aab
3
3
aaa
aab
3
4
aaa
aab
3
all
12
A text of 6 a's and the pattern aab. At each of the 4 places, a and a match, then b differs. 4 times 3 is 12.
why it is allowed: The text is all a, and so is every letter of the pattern but the last. Those match at every place, and the last, b, differs. So all letters are compared at every place.
guess it, then
3the move: multiply by the places
the line:
why it is allowed: By line 2, comparisons at each place, with as by section 4's question 1, line 2. Question 1 made one comparison at each place, in all, by its lines 3 and 4, so there are places. Multiply the two. For 6, 3 times 4, which is 12; for 7, 4 times 4, which is 16.
guess it, then
4the move: a ceiling
the line:
why it is allowed: Half of is at most , a whole number, so rounding it up stays at most . is at most by section 4's question 1, line 5. Multiply the two. For 6, 12 is at most 36.
guess it, then
5the move: read the bound
the line:
why it is allowed: By line 4, with the fixed multiple 1.
guess it, then
6the move: a floor
the line:
why it is allowed: Rounding up never makes a number smaller, so is at least . By section 4's question 1, line 7, is more than . Multiply the two, as times is . For 6, 12 against 9.
guess it, then
7the move: read the bound
the line:
why it is allowed: By line 6, with the fixed multiple a quarter.
guess it, then
8the move: both together
the line:
why it is allowed: Lines 5 and 7 bound by the same growth.
guess it, then
try it with a small : at , line 3 gives , which you can work out by hand