The Case-by-Case Method of Recursive Problem Solving

Peter Mawhorter

January 27, 2023

Land Acknowledgement

This work was done on land stolen from the Massachusett, Wampanoag, and Nipmuck peoples, and the author is grateful for their stewardship of that land in the past, in the present, and in the future. They are still here. The history of this land is important because this work could not have happened without its use. I acknowledge that I directly benefit from this ongoing injustice.

Recursion is Hard

  • Wishful thinking is difficult
  • Students struggle to see patterns
  • Not easy to offer help
  • Case-by-case method avoids wishful thinking
  • Helps students see the structure of solutions
  • Students can solve problems by themselves using this method
  1. Define the base case
  2. Define a “not-quite-base” case
  3. More cases (without recursion)
  4. More cases (recursion to previous cases)
  5. Generalize to “else” case
  6. (optional) Delete unnecessary cases
def countUp(n):
  if n < 0:
    return
  elif n == 0:
    print(0)
  elif n == 1:
    print(0)
    print(1)
  elif n == 2:
    print(0)
    print(1)
    print(2)

  elif n == 3:
    countUp(2)
    print(3)
  elif n == 4:
    countUp(3)
    print(4)
  else:
    countUp(n-1)
    print(n)

Properties

  • Students still have to recognize a pattern of cases
  • First recursion is not scary: calls a known case
  • Lots of examples to work from for the “else” case
  • First few cases provide clear illustration of why/how the recursion works