Lecture 11: April 26, 2023

Reading: zyBooks text, §10.1–10.2, 10.5, 10.8
Assignments: Homework 2 and Extra Credit 2, due May 10

  1. Announcements
    1. New TA office hours on Friday, now 12:00 noon–1:00pm
    2. Tutoring available from the CS Tutoring Club; sign up information in an announcement

  2. Recursion
    1. Expressing a problem in terms of a simpler version of itself — use n!
    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.c, with n = 4
    3. Note nfact calls nfact

  4. Recursive palindrome program
    1. Go through algorithm, working from outside in
    2. Write recursive case
    3. Write base case
    4. Put them together in ispal.c

UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
ECS 36A, Programming & Problem Solving
Version of April 28, 2023 at 11:29PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh