Computer Science Fundamentals (CS153 2003S)

Homework 1: Deep Recursion

Assigned: Wednesday, 29 January 2003
Due: Tuesday, 4 February 2003
No extensions!

Summary: In this assignment, you will investigate an extension of recursion known as deep recursion.

Purposes: To give you more experience in writing recursive procedures.

Collaboration: You should works in groups of two or three. You may also work alone. You may obtain help from anyone you wish, but you should clearly document that help (perhaps with an extra citations page).

Submitting: Use the ECA.


In our normal pattern of list recursion, we recursively apply a procedure procedure to the cdr of the list. However, in some cases, you might also apply the procedure to the car of the list. For example, if we're looking for a value in a list, and that list contains sublists, we might also want to look in the sublists (which means that we should recursively call the procedure on the sublists).

Similarly, if any of those sublists contains its own sublist, we will need to recurse on that sub-sublist. And if the sub-sublist contains another list, we'll also need to recurse on that sub-sub-sublist. And so on and so forth.

The variant of recursion that delves into sublists is often called a deep recursion. To some, it is as natural as flat recursion. To others, it seems like a very different strategy.

Here's a sketch of the form of a deep recursive procedure

(define proc
  (lambda (lst)
      ((null? lst) base-case)
      ((list? (car lst)) (combine-1 (proc (car lst)) (proc (cdr lst))))
      (else (combine-2 (car lst) (proc (cdr lst)))))))


Document and write the following deep-recursive procedures.



Wednesday, 29 January 2003 [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 Tue May 6 09:19:37 2003.
The source to the document was last modified on Wed Jan 29 09:26:27 2003.
This document may be found at

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

Samuel A. Rebelsky,