Fundamentals of Computer Science I: Media Computing (CS151.02 2007F)
[Skip to Body]
Primary:
[Front Door]
[Glance]

[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Assignment]
Groupings:
[Assignments]
[EBoards]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Projects]
[Readings]
[Reference]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151.01 2007F (Davis)]
[CSC151 2007S (Rebelsky)]
[CSCS151 2005S (Stone)]
This lab is also available in PDF.
Summary: In the laboratory, you will explore the running time fo a few algorithm variants.
Contents:
a. In DrScheme, create a new file for this lab, called
analysisexamples.scm
.
b. Add the comments and code for reverse1
, reverse2
,
and myappend
from the
corresponding reading to your file.
a. Add the following line to the beginning of myappend
(again, immediately after the lambda
).
(display (list 'myappend front back)) (newline)
b. Determine how many times myappend
is called when
reversing a list of length seven using reverse1
.
c. Add the following line to the kernel of reverse2
(immediately after the lambda
).
(display (list 'reverse2kernel remaining reversed)) (newline)
d. Determine how many times reverse2kernel
is called when
reversing a list of length seven using reverse2
.
e. Comment out the lines that you just added by prefixing them with a semicolon.
a. Replace the define
for reverse1
with
define$
, as in the following.
(define$ reverse1 (lambda (lst) ...))
b. Find out how many times myappend
is called in reversing
a list of seven elements by entering the following command in the
interactions pane.
> (analyze (reverse1 (list 1 2 3 4 5 6 7)) myappend)
c. Did you get the same answer as in the previous exercise? If not, why do you think you got a different result?
d. One potential issue is that we haven't told the analyst to include
the recursive calls in myappend
. We can do so by replacing
define
with define$
in the definition of
myappend
.
e. Once again, find out how many times myappend
is called
in reversing a list of seven elements by entering the following command
in the interactions pane.
> (analyze (reverse1 (list 1 2 3 4 5 6 7)) myappend)
f. Did you get the same answer as in exercise 1? If not, what difference do you see?
g. Replace the define
in reverse2
with
define$
.
h. Find out how many times reverse2kernel
is called in reversing
a list of seven elements by entering the following command in the
interactions pane.
> (analyze (reverse2 (list 1 2 3 4 5 6 7)) reverse2kernel)
i. Did you get the same answer as in exercise 1? If not, what difference do you see?
In the previous exercise, you considered only a single procedure
in each case (myappend
for reverse1
,
reverse2kernel
for reverse2
). Suppose we
incorporate all of the other procedures. What effect does it have?
a. Find out how many total procedure calls are done in reversing a list
of length seven, using reverse1
, with the following.
> (analyze (reverse1 (list 1 2 3 4 5 6 7)))
b. How does that number of calls seem to relate to the number of
calls to myappend
?
c. Are there any procedures you're surprised to see?
d. Find out how many total procedure calls are done in reversing a list
of length seven, using reverse2
, with the following.
> (analyze (reverse2 (list 1 2 3 4 5 6 7)))
e. How does that number of calls seem to relate to the number of
calls to kernel
?
f. Are there any procedures you're surprised to see?
a. Fill in the following chart to the best of your ability.
List Length  r1: Calls to myappend 
r1: Total calls  r2: Calls to kernel 
r2: Total calls 

2  
4  
8  
16 
b. Predict what the entries will be for a list size of 32.
c. Check your results experimentally.
d. Write a formula for the columns, to the best of your ability.
Here is a third version of rgb.brightest
.
(define rgb.brightest (lambda (colors) (rgb.brightesthelper (car colors) (cdr colors)))) (define rgb.brightesthelper (lambda (brightestsofar remainingcolors) (if (null? remainingcolors) brightestsofar (rgb.brightesthelper (rgb.brighter brightestsofar (car remainingcolors)) (cdr remainingcolors)))))
a. Find out how many steps this procedure takes on lists of length 2, 4, 8, and 16 in which the elements are arranged from lightest to darkest.
b. Find out how many steps this procedure takes on lists of length 2, 4, 8, and 16 in which the elements are arranged from darkest to lightest.
c. Find out how many steps this procedure takes on lists of length 2, 4, 8, and 16 in which the elements are in no particular order.
d. Predict the number of steps this procedure will take on each kind of list, where the length is 32.
http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/History/Labs/analysis.html
.
[Skip to Body]
Primary:
[Front Door]
[Glance]

[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Assignment]
Groupings:
[Assignments]
[EBoards]
[Examples]
[Exams]
[Handouts]
[Labs]
[Outlines]
[Projects]
[Readings]
[Reference]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151.01 2007F (Davis)]
[CSC151 2007S (Rebelsky)]
[CSCS151 2005S (Stone)]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Mon Dec 3 09:54:37 2007.
The source to the document was last modified on Tue Oct 16 10:37:41 2007.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2007F/Labs/analysislab.html
.
You may wish to validate this document's HTML ; ;
Samuel A. Rebelsky, rebelsky@grinnell.eduhttp://creativecommons.org/licenses/bync/2.5/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.