A Beginner's Guide to Tackling Recursion
By Al Sweigart

Between unintelligible algorithms and beautiful fractal artwork, recursion has an intimidating and even mystical reputation. But the underlying ideas behind it are simple. In this tutorial we get a solid foundation of recursive code, and run through several examples in the interactive shell. If you've ever said or thought the words "recursion is confusing", this tutorial is for you.

Saturday 3 p.m.–5 p.m. in Suzanne Scharer

Recursion has an intimidating reputation for being the advanced skill of coding sorcerers. But in this tutorial we look behind the curtain of this formidable technique to discover the simple ideas under it.

If you've ever said or thought the words "recursion is confusing", this tutorial is for you.

Through hands-on exercises in the interactive shell, we'll answer the following questions:

  • What is recursion, and when is it a good idea and bad idea to use it?
  • What are all the confusing ways that recursion is commonly taught?
  • What's a stack, and what's the call stack?
  • What are stack overflows, and how do we avoid them?
  • Do some problems require recursion? How do I transform recursive code into iterative code, and vice versa?
  • What are some common recusive problems in whiteboard coding interviews?
  • What is memoization and tail call optimization?
  • How do I draw that cool-looking fractal artwork using recursion?

We'll cover a number of common recursive algorithms:

  • Factorial and Fibonacci calculation
  • Exponent calculation
  • The Towers of Hanoi
  • The flood fill algorithm
  • Binary search
  • Generating permutations and combinations

This tutorial is for a wide range of developers. Beginners who only understand the basics of Python will be able to follow along. Experienced developers who have hoped no one would notice the recursive-coding gap in their knowledge will be able to breath with relief after taking this tutorial. All that is required is a willingness to learn, and a willingness to have the willingness to learn, and a willingness to have the willingness to have the willingness to learn, and... so on.

Setup Instructions

https://inventwithpython.com/blog/2018/08/24/pyohio-2018-recursion-tutorial/

Al Sweigart

Al Sweigart is a professional software developer and tech book author who teaches programming to kids and adults. Sweigart has written several programming books for beginners, including Automate the Boring Stuff with Python, Invent Your Own Computer Games with Python, and Cracking Codes with Python. His books are freely available under a Creative Commons license at https://inventwithpython.com.

Twitter
Sponsors