Thinking Recursively in Python

Thinking Recursively in Python

Thinking Recursively in Python “Of all ideas I have introduced to children, recursion stands out as the one idea that is particularly able to evoke an excited response.”
– Seymour Papert, Mindstorms Problems (in life and also in computer science) can often seem big and scary. If we keep chipping away at them, more often than not we can break them down into smaller chunks trivial enough to solve.

Dear Pythonic Santa Claus

Santa Claus has a list of houses he loops through

Recursive Functions in Python

A recursive function is a function defined in terms of itself via self-referential expressions

Pesky Details

Python doesn’t have support for tail-call elimination

Maintaining State

Each recursive call has its own execution context, so to maintain state during recursion you have to either: thread the state through each recursive call so that the current state is part of the current call’s execution context

Fin I was once asked to explain recursion in an interview. I took a sheet of paper and wrote Please turn over on both sides. The interviewer didn’t get the joke.

What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment below and let us know.

Recursive Data Structures in Python

A data structure is recursive if it can be defined in terms of a smaller version of itself

Naive Recursion is Naive

Fibonacci numbers were originally defined in the thirteenth century to model the growth of rabbit populations.

Source

Similar products

Get in