notes16 - Iterative processes So far weve been talking...

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 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

Ask a homework question - tutors are online