exercise 1
A size .
worked answer
- is below 300, and is above it.
- , and 512 is at most 600, as the rule says.
Check it another way: , and is above 300, so 300 lies between 256 and 512.
foundations
the puzzle
A job takes steps for items, so items take steps. Only powers of 2 are counted. What can be said about 200 items?
Suppose more items never mean fewer steps. Use the two powers of 2 on either side of 200.
| items | power of 2 below | power of 2 above | steps at least | steps at most |
|---|---|---|---|---|
| 200 | 128 | 256 | 896 | 2048 |
| 20 | 16 | 32 | 64 | 160 |
| 300 | 256 | 512 | 2048 | 4608 |
Every whole from 1 up lies between two powers of 2, . A power of 2 is its own power below: at , and the power above is 256.
Double both sides of : the power above, , is at most .
Halve both sides of : the power below, , is more than .
At , , as the line shows.
Say a count never drops as grows. If , then .
For the job above, , and (lesson 6.4), so .
An upper bound: the power above is at most , so .
A lower bound: gives and , so .
At , and is between 7 and 8. So , and . The formulas use in place of the powers, so they are looser.
Both bounds grow like (lessons 7.3 to 7.5), so this job grows like at every size, not only at powers of 2.
Jeff Erickson's free notes Algorithms, appendix II, also work merge sort's count out only at powers of 2 first. They then show by another method that it holds for every size.
| 0 for odd , for even | ||
|---|---|---|
| 1 | 5 | 0 |
| 2 | 10 | 4 |
| 3 | 15 | 0 |
| 4 | 20 | 16 |
| 5 | 25 | 0 |
| 6 | 30 | 36 |
| 7 | 35 | 0 |
| 8 | 40 | 64 |
mind these
Work each one out. Where there is a box, type your answer and check it. Each exercise's worked answer opens under it.
A size .
Check it another way: , and is above 300, so 300 lies between 256 and 512.
A job's steps never drop as grows, and for items it takes steps.
Check it another way: Both bounds are 3 times a power of 2, and 768 is half of 1536, as the powers are.
A job's steps never drop as grows, and for items it takes steps.
Check it another way: is between 5 and 6, as . So the bound at is below , and 384 is below that.
Three counts, each known at powers of 2.
Check it another way: At the second count is 0, though at 4 it is 16 and at 8 it is 64.