In Class: Week 10, recursion

Create a week10 subdirectory in your cs21/class directory and copy over my starting point files:

    $ cd 
    $ cd cs21/class
    $ pwd

    $ mkdir week10        
    $ cd week10
    $ pwd

    $ cp ~newhall/public/cs21/week10/* .
    $ ls 

  1. Open We are going to write some iterative and recursive versions of the same function. Iterative versions use loops, recursive versions do not use loops, and instead contain calls to themselves. The idea of recursive functions is based on recursive definitions. For example, n! can be defined as n(n-1)!.

    1. Lets try writing recursive factorial together
    2. Next, try writing an iterative version (using a loop) of sumInts that takes a positive int value, n, and returns the sum of the first n integers.
    3. Next, try writing a recursive version of the sum of n ints function.

  2. Open We are going to write some iterative and and recursive functions that operate on lists.