This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Caltech CS 1  Fall 2008 CS1: Introduction to Computation Day 4: October 8, 2008 Dynamic Evolution of Computations Caltech CS 1  Fall 2008 Before we begin... • Let's select house ombudspeople! • Meet at noon on Thursday at the Athenaeum (olive walk entrace) • Starting tomorrow! Caltech CS 1  Fall 2008 Today, let’s think about: • How do our computations unfold? – in space – in time • This will lead us to consider: • efficiency of program execution (first look at a huge subject) Caltech CS 1  Fall 2008 Design and analysis (again) • Last time saw how to design recursive procedures • There are many ways to design a procedure that solves the same problem • Analysis will help us to distinguish "good" solutions from "bad" ones – based on some criterion for "good" and "bad" • Design and analysis always interact! Caltech CS 1  Fall 2008 Example • Recall from last time: (define (sumintegers n) (if (= n 0) (+ n (sumintegers ( n 1))))) Caltech CS 1  Fall 2008 Revisited (summarizing steps) • Evaluate: (sumintegers 3) • (if (= 3 0) 0 (+ 3 (sumintegers ( 3 1)))) • (if #f 0 (+ 3 (sumintegers ( 3 1)))) • (+ 3 (sumintegers ( 3 1))) • (+ 3 (sumintegers 2)) • (+ 3 (if (= 2 0) 0 (+ 2 (sumintegers ( 2 1))))) • (+ 3 (+ 2 (sumintegers 1))) • (+ 3 (+ 2 (if (= 1 0) 0 (+ 1 (suminteger ( 1 1)))))) Caltech CS 1  Fall 2008 Revisited (summarizing steps) • (+ 3 (+ 2 (+ 1 (sumintegers 0)))) • (+ 3 (+ 2 (+ 1 (if (= 0 0) 0 …)))) • (+ 3 (+ 2 (+ 1 (if #t 0 …)))) • (+ 3 (+ 2 ( + 1 0))) • … • 6 Caltech CS 1  Fall 2008 Evolution of computation • (sumintegers 3) • (+ 3 (sumintegers 2)) • (+ 3 (+ 2 (sumintegers 1))) • (+ 3 (+ 2 (+ 1 (sumintegers 0)))) • (+ 3 (+ 2 (+ 1 0))) Caltech CS 1  Fall 2008 What can we say about the computation? On input N : • How many calls to sumintegers ? N+1 • How much work per call? (sumintegers 3) (+ 3 (sumintegers 2)) (+ 3 (+ 2 (sumintegers 1))) (+ 3 (+ 2 (+ 1 (sumintegers 0)))) (+ 3 (+ 2 (+ 1 0))) Caltech CS 1  Fall 2008 Work per call? • (+ 3 (sumintegers 2)) • (+ 3 (if (= 2 0) 0 (+ 2 (sumintegers ( 2 1))))) • (+ 3 (+ 2 (sumintegers 1))) compare if add * add call *(subtract costs same as add) Caltech CS 1  Fall 2008 What can we say about the computation? on input N : • How many calls to sumintegers ? N+1 • How much work per call? constant • one comparison, one if , two additions, one function call (at most) • How many deferred operations at end? (sumintegers 3) (+ 3 (sumintegers 2)) (+ 3 (+ 2 (sumintegers 1))) (+ 3 (+ 2 (+ 1 (sumintegers 0)))) (+ 3 (+ 2 (+ 1 0))) Caltech CS 1  Fall 2008 Deferred operations? • (+ 3 (+ 2 (+ 1 0))) • Last call to sumintegers gives the result – base case • but have to use this result to "finish up" computations that were previously started to get final result • We call those incomplete computations deferred operations or pending operations Caltech CS 1  Fall 2008 What can we say about the...
View
Full
Document
This note was uploaded on 09/25/2010 for the course CS 1 taught by Professor Chang during the Spring '08 term at UMBC.
 Spring '08
 chang

Click to edit the document details