3.57 Exercise 3.57
When computing fibs using the definition presented earlier, one addition is performed for each value of the stream besides the first two. This is because values of the stream aren’t calculated multiple times – in other words, because the delay special form memoizes values. If this were not the case, then the situation would be much different:
(stream-ref fibs 2) would need to perform one addition
(stream-ref fibs 3) would need to perform two additions: One for the last value in fibs and one more
(stream-ref fibs 4) would need to perform four additions: Two for the last value, one for the value before that, and one more
(stream-ref fibs 5) would need to perform seven additions: Four for the last value, two for the value before that, and one more
(stream-ref fibs 6) would need to perform twelve additions: Seven for the last value, four for the value before that, and one more
The growth in the number of additions is O(2^n). (This is not a tight bound, but the growth of the sequence is clearly exponential.)