Lecture 17 Outline (November 2, 2015)

Reading: text, §9


  1. Greetings and felicitations!
    1. Homework 3 is out – 20 extra points if in by Wednesday, 10 if by Friday; due Monday, November 9
    2. Extra Credit 1 due tonight
    3. Extra Credit 2 is out and due November 9

  2. Recursion
    1. Expressing a problem in terms of a simpler version of itself — use n! and searching a character string
    2. Function calling itself
    3. Similar to mathematical induction, but backwards
    4. Structure: base case, recursive case
    5. What happens if you omit the base case? (Bad things …)

  3. How it works
    1. Program stack
    2. Walk through nfact, with n = 4
    3. Note nfact calls nfact

  4. The argument list
    1. Go through how main in nfact.c gets integer

  5. Recursive greatest common divisor
    1. Go through Euclidean algorithm for computing gcd
    2. Walk through function gcd, with m = 4 and n = 6
    3. Do it again with m = 14 and n = 35
    4. Go through program gcd.c


You can also obtain a PDF version of this. Version of November 3, 2015 at 12:22AM