4 ms·
I find recursion can be just as simple to explain. Start with a basket of tomatoes and a bowl. If there are no tomatoes in the basket, you’re done. Otherwise:
by sdedovic 5y ago
I find recursion can be just as simple to explain.
Start with a basket of tomatoes and a bowl. If there are no tomatoes in the basket, you’re done. Otherwise: Take one tomato. Dice it. Put the output in the bowl. Recur.
- zug_zug 5y agoI'm meh on that example (hard to say it's not a while loop), but I agree that humans already understand and execute recursion in their day-to-day life, so it is a communication thing. How about this example as an example of recursion: Looking up a word in a dictionary (a real-life binary search).
- allturtles 5y agoHave you actually explained it to people that way and had them get it? I think most people would just understand what you described as an iterative process, and understand recur as being no different than repeat.
- mimixco 5y agoIndeed. Recursion requires that a procedure calls (or recurses over) itself.
- mimixco 5y agohttps://en.wikipedia.org/wiki/Recursion https://en.wikipedia.org/wiki/Recursion https://www.lexico.com/definition/recurse https://www.lexico.com/definition/recurse
- zozbot234 5y agoIteration (repetition) is a special case of recursion where the recursive action is always the final step in the process; it's a kind of recursion that dispenses with the need to track a stack of process activations. So it's quite possible to teach both in the same context.