Computer Science Fundamentals (CS153 2004S)
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Search]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[Experiments in Java]
[Java API]
[Scheme Reference]
[Scheme Report]
[CS153 2003S]
[CS151 2003F]
[CS152 2000F]
[SamR]
Back to Higher-Order Procedures (3). On to Algorithm Analysis (1).
Held: Friday, 20 February 2004
Summary: Today we revisit recursion and consider a more efficient way to write recursive procedures. This new technique is called tail recursion.
Related Pages:
Assignments:
Notes:
Overview:
add-to-all, factorial,
traditional right-associative sum.
member?, the left-associative sum.
sum (in class).
sum.scm for details.
(1 2 3 4) and see if one seems
to be easier to deal with.
(sumr (1 2 3 4)) --> (+ 1 (sumr (2 3 4))) --> (+ 1 (+ 2 (sumr (3 4)))) --> (+ 1 (+ 2 (+ 3 (sumr (4))))) --> (+ 1 (+ 2 (+ 3 4))) --> (+ 1 (+ 2 7)) --> (+ 1 9) --> 10
(suml (1 2 3 4)) --> (suml-helper (1 2 3 4) 0) --> (suml-helper (2 3 4) 1) --> (suml-helper (3 4) 3) --> (suml-helper (4) 6) --> 10
things to do once the recursion reaches the base case.
suml:
accumulatespartial solutions. Hence, we often call it an accumulator.
oldbase case (the one in the non-tail-recursive procedure).
Back to Higher-Order Procedures (3). On to Algorithm Analysis (1).
[Skip to Body]
Primary:
[Front Door]
[Current]
[Glance]
-
[Honesty]
[Instructions]
[Links]
[Search]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Readings]
[Reference]
Misc:
[Experiments in Java]
[Java API]
[Scheme Reference]
[Scheme Report]
[CS153 2003S]
[CS151 2003F]
[CS152 2000F]
[SamR]
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 Fri May 7 09:43:13 2004.
The source to the document was last modified on Thu Feb 19 21:30:41 2004.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS153/2004S/Outlines/outline.19.html.
You may wish to
validate this document's HTML
;
;
Check with Bobby