Teaching Iteration and Recursion in Chapter 7

Today I taught the first part of chapter 7, which focused on introducing iteration and recursion through evaluating palindromes.  I essentially used the monitor to type my code for the three different methods on the screen.  The python web browser we originally used appeared to be for python 3, so my code did not properly run, but I was still able to take my participants through the mechanics of creating the functions.  I introduced the first method, which creates a copy of the word, reverses it, and compares it to the original.  I introduced iteration, which compares the first letter to the last, second letter to second to last, etc.  Finally I introduced recursion, in which the function calls itself to complete a task.  I also went over some of the costs and benefits of each method.  For example, the first method looks neat and clean, but could hog up memory by having to create a copy.  In contrast, iteration creates a longer method, but resolves the memory issue.  My main self-criticism is that I only have a more general understanding of recursion as a principle and I was not able to fully explain each individual component of the recursion method.  But my hope is that my examples were able to provide my participants with a solid overview of iteration and recursion as problem-solving methods and coding tools.  The following are screenshots of my version of the three functions, which I retyped and displayed during the lesson.

palindrome-1 palindrome-2

Leave a Reply

Your email address will not be published. Required fields are marked *