Fundamentals of CS I (CS151 2002F)

Homework 8: Tail Recursion

Assigned: Friday, November 15, 2002
Due: Wednesday, November 20, 2002
No extensions!

Summary: In this assignment, you will consider a few of the more problematic issues in tail recursion.

Purposes: To give you more experience working with tail recursion and higher-order procedures.

Collaboration: Although you may certainly discuss this assignment with anyone, you should each turn in your own solution.

Assignment:

1. Consider the efficient exponent procedure we wrote in class. Rewrite that procedure to be tail recursive.

2. Rewrite insert-right to be tail recursive.

3. Here's a non-tail-recursive version of append.

(define append
  (lambda (list-one list-two)
    (if (null? list-one) list-two
        (cons (car list-one)
              (append (cdr list-one) list-two)))))

a. Write your own tail-recursive version.

b. Determine experimentally which of the three versions (built-in, given above, tail-recursive) is fastest.

 

History

Friday, 14 November 2002 [Samuel A. Rebelsky]

 

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 Wed Dec 4 08:45:40 2002.
The source to the document was last modified on Fri Nov 15 08:49:19 2002.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2002F/Homework/hw.08.html.

You may wish to validate this document's HTML ; Valid CSS! ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu