I disagree with the reasoning for why factorial is a bad example. Factorial is very simple to explain as a mathematical function, requires very little prior knowledge. When asked why you aren't allowed to implement it as a loop, the response I was given was that you very simply define factorial in a self referential way (0! = 1 and n! = n * (n - 1)!), and is there any way you could implement the function in a way tha…
I agree factorial is very clearly defined with self-references but I think that the answers have no clear meaning and that's why its not an optimal way of teaching recursion. Teaching examples that have meaningful answers IMO allow for much better reasoning
How not to teach recursion (2021)
111–120 of 121 posts
Re: How not to teach recursion (2021)
#112I agree with the overall sentiment. I taught for awhile and was happy with the approach I came up with. Students start out with the basics of learning how to loop through a list to transform some data. Once they have looping down, they are introduced to map and other built in methods. But, before using these methods, they are tasked with rewriting them using the looping they've learned. Once they've "earned" the usag…
> but this time without using any kind of looping. See, to me, recursion is a kind of looping.
Re: How not to teach recursion (2021)
#113I've been a SWE for 12 years and has been teaching people how to code during my free time ever since I started coding (so more than 12 years of teaching). I have taught around 30 students over the past 12 years who went from knowing nothing to getting a SWE job and from my limited dataset I have observed that: 1. Students who were taught for/while loops first has a hard time grasping recursion. I suspect it is becaus…
There have been various studies that agree with you: teaching recursion before iteration seems to have benefits! From my experience, it seems to be extremely unpopular among teachers due to the claim that recursion is "useless in industry". My personal opinion is that learning recursion first is probably a step in the right direction, but I'm curious to hear your thoughts (in terms of their claims of the usefulness of recursion in industry).
Re: How not to teach recursion (2021)
#114Earlier quoted context omitted.
Was there a link on the web page pointing to the author? I must have overlooked it somehow.
The home page has it: https://parentheticallyspeaking.org/
Re: How not to teach recursion (2021)
#115> For instance, even a child informed about biology can answer basic questions like these: - Does a child have (biological) parents? - Yes. - How many? - Two, a (biological) male and (biological) female. [...] They can similarly see other kinds of self-referential data even at a young age, well before they program. Isn’t this a horrific example for recursion? Wouldn’t most adults realise that the structure isn’t a tr…
How is a family TREE not a tree
An actual family tree is not even a DAG because the nodes are unknown, and “parents” is an extremely fuzzy concept. Where does adoption fit it? What about step-parents? How do you record uncertainty? Etcetera.
One of my friends in another country had a kid with her first cousin, and parents can be more closely related biologically.
It is less than one hundred generations before we find a single common ancestor to everyone alive[3]. Also see [4][5].
Regardless, anyone that thinks using a family tree as a teaching example for children should have a reëducation holiday .
[1] https://en.wikipedia.org/wiki/Tree_(data_structure)
[2] https://en.wikipedia.org/wiki/Directed_acyclic_graph
[3] https://www.scientificamerican.com/article/humans-are-all-mo...
Re: How not to teach recursion (2021)
#116I've been a SWE for 12 years and has been teaching people how to code during my free time ever since I started coding (so more than 12 years of teaching). I have taught around 30 students over the past 12 years who went from knowing nothing to getting a SWE job and from my limited dataset I have observed that: 1. Students who were taught for/while loops first has a hard time grasping recursion. I suspect it is becaus…
My background is in teaching CS1 courses in undergrad (as a TA). There have been various studies that agree with you: teaching recursion before iteration seems to have benefits! From my experience, it seems to be extremely unpopular among teachers due to the claim that recursion is "useless in industry". My personal opinion is that learning recursion first is probably a step in the right direction, but I'm curious to…
From my experience its true. I have never written recursive code in my 12 years of professional experience (primarily JS).
But during interviews, I have written recursive solutions many times to solve some of the harder problems.
Re: How not to teach recursion (2021)
#117It also helps if students have been exposed to the idea of recursion in math, for example by sequences where a_n is defined in terms of a_{n-1}, and/or proofs by induction.
Re: How not to teach recursion (2021)
#118Re: How not to teach recursion (2021)
#119Earlier quoted context omitted.
>i think the problem is that most people try to follow the recursions in their head which is hard. It's hard for computers, too as it can easy result in stack overflow if there are too many steps.
that's the obvious issue. another less intuitive one is that modern cpus and compilers are essentially optimized for iterative algorithms. state variables can be kept in registers, simd can be used for data that appears in contiguous arrays, caching is built on locality assumptions and data locality is preserved. non-flattened recursive algorithms spread their state across linear memory with a full stack frame for ev…
Re: How not to teach recursion (2021)
#120The fact that the recursive method for calculating factorials fails for quite small numbers is a good reason for teaching it. Also it's a good illustration of how useless recursion is in practice.
Iterative methods for calculating factorials also "fail for quite small numbers" in most common languages (basically, anything without built-in bignums). The cause of failure in this case has nothing to do with recursion.
It's also useful to learn that despite the love of recursion among computer scientists, in practice it's barely if ever a good idea.