Unformatted text preview: • Iterative processes So far we’ve been talking about time efficiency, but there is also memory (space) efficiency. This has gotten less important as memory has gotten cheaper, but it’s 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
This note was uploaded on 02/17/2010 for the course COMPUTER S 26275 taught by Professor Harvey,b during the Spring '10 term at Berkeley.
- Spring '10