 |
|
|
|
Solutions for Session 3, Part B
See solutions for Problems: B1 | B2 | B3 | B4
 |
Problem B1 | |
a. | The output is 12. |
b. | The output is 16. |
c. | For an input n, the algorithm performs n >> 2n >> 2n + 2 >> n + 1 >> n - 6 >> 4n - 24. |
d. | Knowing that the output is 4n - 24 means that we have to solve 4n - 24 = 28, an equation that is solved by n = 13. This means that the input must be 13. |
e. | The input is 14. |
f. | The input is 18. |
g. | The input is 15. |
<< back to Problem B1
|
|
|
 |
Problem B2 | |
Working backwards from the end of the algorithm to the beginning will undo it. There are other strategies, such as writing equations for each of (d)-(g).
<< back to Problem B2
|
|
|
|
 |
Problem B3 | |
Algorithm B "undoes" everything that Algorithm A does.
| Take the input (the output of Algorithm A) and |
| Divide it by 4 |
| Add 7 |
| Double it |
| Subtract 2 |
| Halve that |
| There's your output (of Algorithm B) |
<< back to Problem B3
|
|
|
|
 |
Problem B4 | |
Test it out. See if you can figure out why it works by thinking of the algorithms as driving directions. Where would you end up if someone gave you directions like Algorithms A and B, and asked you to do them both? In short, yes, they undo each other.
<< back to Problem B4
|
|
|