12: Recursion
( \newcommand{\kernel}{\mathrm{null}\,}\)
- 12.0: Introduction
- This page discusses recursion, a programming technique that simplifies complex solutions by allowing functions to call themselves with varying parameters. It highlights the compactness and efficiency recursion brings to programming, especially in advanced scenarios.
- 12.1: Recursion Basics
- This page explains recursion as a problem-solving technique that simplifies complex problems by addressing simpler variants. It highlights applications like the Tower of Hanoi, detailing the recursive method for moving rings. Engaging questions help readers comprehend the steps needed for two, three, and four rings. The primary focus is on understanding how recursion aids in systematically constructing solutions.
- 12.2: Simple Math Recursion
- This page focuses on learning about recursive algorithms, specifically in calculating factorials. It defines factorials recursively, emphasizing recursive and base cases, and discusses Python's recursive function structure with essential stopping conditions. It provides examples like summation and Fibonacci sequences for practice and includes programming exercises to deepen understanding of recursion.
- 12.3: Recursion with Strings and Lists
- This page outlines learning objectives centered on using recursion in programming to solve string and list-related problems. It explains palindromes and how recursion can identify them, alongside the count() function for lists. The page includes checkpoints for understanding palindromes and list permutations, as well as practical exercises like creating a function to remove duplicates. Additionally, multimedia content is mentioned to enhance the learning experience.
- 12.4: More Math Recursion
- This page covers the implementation of recursive functions for calculating Fibonacci numbers and the greatest common divisor (GCD) using Euclid's method. It explains the Fibonacci sequence, including a recursive function and example output. The GCD section defines the method and illustrates its recursive calculation with an example. Additionally, the text provides practice questions and encourages writing more recursive functions.
- 12.5: Using Recursion to Solve Problems
- This page explores recursion in searching lists and solving the Three Towers problem. It details binary search, a recursive method for sorted lists that halves the search space by checking the middle element. The Three Towers problem is similarly approached with recursion, organizing rings based on subproblems. Code examples highlight how recursion simplifies complex issues, enhancing efficiency in searching and problem-solving.
- 12.6: Chapter Summary
- This page discusses recursion and its ability to simplify complex problems by dividing them into smaller cases. It covers identifying recursive and base cases, computing factorials, and solving problems with strings and lists. Additionally, it addresses Fibonacci number generation, efficient list searching, and the Three Towers problem, as well as introducing the built-in count() function for counting list elements, thereby equipping readers with practical recursion skills.