CSC 151.01, Class 46: Analyzing Procedures
Overview
- Preliminaries
- Notes and news
- Upcoming work
- Extra credit
- Questions
- A quick overview
- Lab
- Debrief
News / Etc.
- New partners! (Keep these partners tomorrow.)
- We have the evil Friday at 2:00 p.m. final exam time. But I think I can argue that we can use the Thursday 9:00 a.m. final exam time. https://www.grinnell.edu/about/offices-services/registrar/calendars/exams You could also take it during the other section’s time, Friday at 9:00 a.m.
Upcoming Work
- Lab writeup: TBD.
- Project sketches due NOW
- Reading for Wednesday: Association Lists
- Quiz Friday.
- Projects due next Tuesday.
Extra credit (Academic/Artistic)
- CS Table TODAY, noon: Algorithm [sic] accountability
- CS Extras Thursday, 4:15pm: Project Gadfly
Extra credit (Peer)
- AAA hosts Kit Yan performing Queer Heartache, Wednesday, Harris, 7pm.
- Ooh and Ah at the Water Bottle dress in Dance Ensemble show, Staying with the Trouble. Tickets are available in Bucksbaum box office for Thu, Fri, Sat at 7:30 and Sunday at 2:00.
- LINK, Saturday, 1-4pm. Selling food. Eat!
- Drill Team Show, May 5, at Triple V stables (alternately, W+V stables); the other side of the golf course. Free rides (cars, not pony) to the event!
- Next home baseball game: May 7 (Senior Day)
Extra credit (Misc)
- May 4 town hall on belonging. 11am, May 4, JRC 101
- Raising of Peace Rock today at 11am.
Other good things to do
- Dag Field Day, Saturday, April 29, noon-5pm, in the Club Athletic Field.
- Raging Cow Atlatl event, Saturday, near Softball field.
- Careers in Finance symposium.
- Titular head (?); Tickets today at noon at Bucksbaum.
Questions
- Will you open the shades?
- Thanks!
A quick overview
- We don’t always think carefully about the “cost” of a procedure.
The number of steps; the number of calls. For example, until we
looked carefully at the implementation of lists,
length
seemed “cheap”. - Amazingly, even knowing those costs, we sometimes mis-estimate.
- To help learn better, we should annotate our programs so that they count calls, and then look at those counts.
- We have magic counters.
- Create a counter.
(define cons-counter (counter-new "cons"))
- Write an alternative to the base procedure that updates the counter.
(define $cons (lambda (a b) (counter-count! cons-counter) (cons a b)))
- Update our procedures that use that procedure to use the new version
(define not-reverse
(lambda (lst)
(if (null? lst)
null
(cons (car lst) (not-reverse (cdr lst))))))
(define not-reverse
(lambda (lst)
(if (null? lst)
null
($cons (car lst) (not-reverse (cdr lst))))))
- Question: Could we rewrite
length
so that it stops when it hits - too many
cons
cells? - Yes. What a good idea. Next exam.
Lab
- How many calls to
list-append
will there be if we write (list-append lst 'a)
?(length lst)
+ 1.- It recurses through the list until the end, plus one more call
- What happens in terms of append when we call
(list-reverse-1 (0 1 2 3 4 5 6))
? (append (reverse (1 2 3 4 5 6)) (list 0))
- Seven calls to append
- To compute
(reverse (1 2 3 4 5 6))
, we have to(append (reverse (2 3 4 5 6)) (list 1))
- Six calls to append
- To compute
(reverse (2 3 4 5 6))
,(append (3 4 5 6) (list 2))
. - Five calls
- …
- List of length seven, 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28
Can we generalize? (Will you tell us the story about Gauss?)