This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Iterative processes So far weve been talking about time efficiency, but there is also memory (space) efficiency. This has gotten less important as memory has gotten cheaper, but its still somewhat relevant because using a lot of memory increases swapping (not everything fits at once) and so indirectly takes time. The immediate issue for today is the difference between a linear recursive process and an iterative process . ;;;;; In file cs61a/lectures/1.2/count.scm (define (count sent) (if (empty? sent) (+ 1 (count (bf sent))) )) This function counts the number of words in a sentence. It takes ( N ) time. It also requires ( N ) space, not counting the space for the sentence itself, because Scheme has to keep track of N pending computations during the processing: (count (i want to hold your hand)) (+ 1 (count (want to hold your hand))) (+ 1 (+ 1 (count (to hold your hand)))) (+ 1 (+ 1 (+ 1 (count (hold your hand))))) (+ 1 (+ 1 (+ 1 (+ 1 (count (your hand))))))...
View Full Document
- Spring '10