They don’t mention “divide and conquer” at all, which I find a pretty compelling use of recursion even for non-inherently recursive problems. Writing a merge sort recursively is much easier and clearer than the nonrecursive variant.
How not to teach recursion (2021)
31–40 of 121 posts
Re: How not to teach recursion (2021)
#32> Towers of Hanoi This also suffers from having a non-recursive solution, using bit-manipulation of a binary counter: max = 1
Re: How not to teach recursion (2021)
#33I always thought Euclid's algorithm had a pretty great runtime complexity, compared to "list all divisors, choose the greates common one". Is that not correct?
Re: How not to teach recursion (2021)
#34They don’t mention “divide and conquer” at all, which I find a pretty compelling use of recursion even for non-inherently recursive problems. Writing a merge sort recursively is much easier and clearer than the nonrecursive variant.
The divide-and-conquer algorithm is a subset of what the post calls generative recursion, which requires a non-trivial amount of logic to get it right (even the simplest algorithm like binary search can be surprisingly difficult).
Re: How not to teach recursion (2021)
#35I feel like I've read this before
Re: How not to teach recursion (2021)
#36I would teach it like this: https://news.ycombinator.com/item?id=31782387
Re: How not to teach recursion (2021)
#37Re: How not to teach recursion (2021)
#38First of all, do not tell students to "start with the base case". The base case will be trivial and gives very little insight into how to solve the recursion problem. All the time they spend thinking about that is time spent not confronting the actual problem.
Beyond that, I think the way to teach recursion is to say "You cannot write the code until you can write a sentence in words describing the recursive solution. Your sentence must make reference to calling the procedure on a smaller sub-problem. Don't bother describing the base case in the sentence; it's boring - just fill it out when you write the code.".
So something like "The number of ways the robot can get to the last square is equal to the number of ways it can do it assuming it starts by going right plus the number of ways it can do it assuming it starts by going down".
Re: How not to teach recursion (2021)
#39The best summary I’ve heard and remembered was from my undergraduate data structures professor over 30 years ago. It has a nice rhyming structure: “every recursive function has a base case and a smaller caller.”
What does smaller caller mean in this case?
Though, there is also the Ackermann function... so for some recursive functions it is not be as easily seen why they would terminate.
Re: How not to teach recursion (2021)
#40The best summary I’ve heard and remembered was from my undergraduate data structures professor over 30 years ago. It has a nice rhyming structure: “every recursive function has a base case and a smaller caller.”
What does smaller caller mean in this case?