Draw the tree illustrating the process generated by the count-change
procedure of Section 1.2.2 in making change for 11 cents. What are the
orders of growth of the space and the number of steps used by this
process as the amount to be changed increases.
Tikz code for image on GitHub.
The sine of an angle (in radians) can be computed by making use of the approximation $\sin x\approx x$ if $x$ is sufficiently small, and the trigonometric identity
to reduce the size of the argument of $\sin$.(For the purposes of this exercise an angle is considered “sufficiently small” if its magnitude is not greater than 0.1 radians.) These ideas are incorporated in the following procedures:
(define (cube x) (* x x x))
(define (p x) (- (3 x) (* 4 (cube x))))
(define (sine angle)
(if (not (> (abs angle) 0.1))
angle
(p (sine (/ angle 3.0)))))
p
applied when (sine 12.15)
is
evaluated?sine
procedure when (sine a)
is evaluated?p
is applied the same numbers of times as the angle
needs to be divided by 3 before the result is less that 0.1 radians.
So p
is applied 5 times in the evaluation of (sine 12.15)
.(sine n)
is
$\Theta(\log n)$ in space and since the procedure is a linear
recursion the procedure is also $\Theta(\log n)$ in space.