Python (Fall 2026) Module 13-1: Introducing Recursion
Watch on YouTube →
Overview
Bill Moseley introduces recursion as a function calling itself, a technique that can solve problems in ways that are sometimes simpler and less error-prone than nonrecursive alternatives. Fractals, Romanesco broccoli, a turtle-drawn branching tree, and the dream-within-a-dream structure of Inception illustrate self-similarity, recursive calls, and the need for an end case.
Key takeaways
- A recursive function calls itself, creating nested calls that continue until a defined end case is reached.
- The end case prevents recursion from continuing indefinitely; in Moseley's turtle tree, recursion stops when branches become short enough.
- After the end case is reached, nested function calls return outward, similar to waking from successive dream levels in Inception.
- Fractals make recursion visible through self-similarity, including repeating spiral forms and the branching structure of Romanesco broccoli.
- Moseley's turtle-drawn tree demonstrates how changing the branching factor and minimum branch length changes a recursive design.
- Recursion is not always necessary, but it can make some solutions less laborious and less error-prone than their nonrecursive alternatives.
Chapters
- The one-day module is a sandbox with no assignment because recursion is an advanced, specialized topic.
- Computer science, advanced mathematics, data science, and advanced programming are areas where recursion can be useful.
- Many recursive problems have nonrecursive solutions, but those alternatives can take more work and be more prone to errors.
- A fractal repeats a design inside smaller versions of itself, as shown by a spiral pattern that continues at finer scales.
- Romanesco broccoli displays repeating conical, spiral-like shapes, with smaller forms resembling the larger structure.
- In Moseley's fractal tree, each branch splits into four smaller branches, repeating the pattern at reduced sizes.
- A turtle program draws a tree by splitting each branch into two until it reaches a specified minimum length.
- Changing the branching factors can produce different tree designs, such as branches that split into three, four, or six parts.
- Inception's dream-within-a-dream structure illustrates nested function calls that return outward after reaching an end case.
- Recursion is defined as a function that contains a call to itself; the tree's short-branch threshold is its end case.
Transcript excerpt
0:04 All right, welcome back everyone. Happy Wednesday. Today we are doing our last one-day module, and the good news is that today's module does not carry an assignment with it. It's just a sandbox. The reason for that is because the topic for today is somewhat obscure. However, if you are majoring in computer science, or plan to major in computer science, or plan to do any sort of advanced mathematical explorations, data science, or any sort of advanced programming, this can come in very handy. So for some of you, this will just be sort of a, that's kind of interesting module. For others of you, this will be something that you will return to later on if you're in
1:01 computer science. Recursion is somewhere between a mathematical concept and a computer science tool. But it's a code structure, and it's a, it's a way of doing things that is rarely required. What I mean by that is that in almost every case where you might use recursion to solve a problem, you could do it another way. You could do it another way. Now, in some cases, those other ways of doing things that are not recursive are a lot more work, a lot more difficult, and more prone to errors. This is a visual example of recursion. For those of you that are interested
1:56 in mathematical concepts, you might recognize this image. Anybody know what this is called? So, no math nerds in here. I see. Okay, that's fine. We can be, there are nerds of all kinds. This is called a fractal. Have you heard the term? Probably somewhere. This is a fractal image. And what makes it a fractal image is that it's a design that is made up of smaller versions of itself. Now, if you look at this for a second, you can probably make sense of
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Bill Moseley, Ph.D. - Computer Science Educator.