notes16 - • Iterative processes So far we’ve been...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

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.

Ask a homework question - tutors are online