Handout 14C

The purpose of this exercise is to study the way recursive procedures return information to the procedure that calls them.

It is not too difficult to understand recursive procedures that draw ferns or spirals. It is, however, difficult to learn (and to teach!) how recursive procedures output information. We've seen an example of a recursive procedure that reverses a list and one of a recursive procedure that computes the GCD. Now we will examine the GCD procedure more closely.

Below are instructions to a family of Zeeps on how to compute the GCD. Follow these instructions in the in-class exercise.

  1. Wait until someone hands you a piece of paper with two numbers written on it.

  2. Divide the bigger number by the smaller one and write down the remainder.

  3. If the remainder is zero, write the smaller of the first two numbers on a piece of paper and give it back to the person who gave you the two numbers.

    If the remainder is not zero, do the following:

    1. Write the smaller number and the remainder on a piece of paper and hand it to someone who hasn't gotten one yet. Wait for them to give you a piece of paper back.

    2. Give the paper you get back to the person who handed you the piece of paper with two numbers on it.


Mtht420