Skip to content

Recursion Tutoring Session Prompt

Copy and paste this prompt to start your tutoring session about recursion in Python:


Hi! I'm a student in CS 5001/5002 and I need help understanding recursion in Python. We're currently in Week 4 of our integrated course where we're learning how mathematical induction and recursive programming connect to each other.

My current understanding level:

  • I've watched the pre-class videos about recursion
  • I understand what a function is and how to write basic functions
  • I'm familiar with loops (for and while)
  • I know basic Python syntax

What I'd like to focus on today:

Please help me understand recursion by covering these topics in order:

  1. The Core Concept: What does it mean for a function to "call itself"? How is this different from a loop?

  2. The Mathematical Connection: How does recursive thinking relate to mathematical induction? Can you show me how the base case and recursive case in code mirror the base case and inductive step in mathematical proofs?

  3. Essential Components: Every recursive function needs:

    • A base case (when to stop)
    • A recursive case (how to break down the problem)
    • Progress toward the base case

    Can you help me identify these in examples?

  4. Classic Examples: Please walk me through these step-by-step:

    • Factorial calculation: factorial(n) = n * factorial(n-1)
    • Fibonacci sequence: fib(n) = fib(n-1) + fib(n-2)
    • Show me the "call stack" - how Python keeps track of function calls
  5. Debugging Recursion: How do I trace through recursive calls? What are common mistakes and how do I avoid infinite recursion?

  6. When to Use Recursion: When is recursion better than loops? When should I avoid it?

My specific questions:

[Add any specific questions you have here, such as:] - I'm confused about how the computer "remembers" where it was in each function call - I don't understand how the base case actually stops the recursion - Can you help me write a recursive function to [specific problem]? - I'm getting a "maximum recursion depth exceeded" error - what does this mean?

Learning style preference:

  • I learn best with visual diagrams showing the call stack
  • I prefer step-by-step code tracing
  • I like connecting to real-world analogies
  • I want to see the mathematical proof alongside the code

Please start with the basics and build up gradually. I'd like to write and test code together as we go, and I want to understand both the "how" and the "why" behind recursion. Thanks!


Additional Resources

Pre-Class Videos (Review These First!)

Mathematical Connection (CS 5002)

Quick Reference

Basic Recursive Function Template:

def recursive_function(parameter):
    # Base case - when to stop
    if base_condition:
        return base_value

    # Recursive case - break down the problem
    else:
        return recursive_function(modified_parameter)

Common Recursion Patterns: - Countdown: countdown(n-1) - Mathematical sequences: factorial(n-1), fibonacci(n-1) + fibonacci(n-2) - Divide and conquer: Split problem in half, solve each half - Tree traversal: Process current node, recurse on children


This prompt is designed to help you get comprehensive, targeted help with recursion while connecting it to the mathematical induction concepts we're learning in our integrated CS 5001/5002 course.