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
      /home/your_user_name/cs21/class

    $ mkdir week10        
    $ cd week10
    $ pwd
      /home/your_user_name/cs21/class/week10

    $ cp ~newhall/public/cs21/week10/* .
    $ ls
      list_recursion.py  recursion.py 
	

  1. Open recursion.py. 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 list_recursion.py. We are going to write some iterative and and recursive functions that operate on lists.