← Back to the Introduction to Computer Science outline The Course Maker
← Introduction to Computer Science outline
Week 14 · Module overview

Week 14 — Recursion

Introduction to Computer Science Free sample edition

Welcome to your Week 14 Start Here page.

Why this matters

A biology student counting the photos in a folder that holds more folders and a business major totaling a budget whose categories split into smaller categories both face a job that holds smaller copies of itself. Recursion is how a program solves that kind of job.

In plain language

Some jobs are easier to describe as a smaller copy of themselves. Counting down from 3 is saying 3 and then counting down from 2. This week you learn recursion (a way of solving a problem by having a function call itself on a smaller copy of the same problem). Every recursive function needs a place to stop, and you will see what happens when one is missing. As always, you predict what each program prints and then run it to check.

  • Already covered: functions and frames from Week 7, and slices from Week 9.
  • This week: base cases, factorial, the call stack, and RecursionError.
  • How they connect: every recursive call is a Week 7 call with its own frame.
  • Where we're going next: Week 15, a first class and its objects.

Focus

What happens when a function calls itself, and how does it ever stop?

By the end of this module, you should be able to:

  • [ ] name the base case and the recursive case
  • [ ] trace factorial and the call stack, call by call
  • [ ] explain why a missing base case raises RecursionError

To-do

Plan your week

  1. Read Chapter 14 (about 45 minutes), then the lecture and slides.
  2. Work the lecture tutorial (60–90 minutes) and the practice set (about 20 minutes).
  3. Do the Coding Lab (about 90 minutes), the discussion, and the assignment.
  4. Take the quiz.

This week's checkpoint: predict what countdown(3) prints, run it, and explain why Go! comes last.

You've got this

Predict, then run, and ask your instructor if a step snags.

Built with The Course Maker · samples.thecoursemaker.com