Where is recursion applied in industrial programming. I do understand the notion that it is a function that calls itself but my question is what's its major use in programming paradigm
Asked
Active
Viewed 21 times
-2
-
the major use is to simplify the algorithm – mangusta Aug 31 '21 at 18:03
-
Welcome to SO! This is pretty broad. It's like asking "what can I build with wood?" The answer is: lots of stuff. Have you read [What is recursion and when should I use it?](https://stackoverflow.com/questions/3021/what-is-recursion-and-when-should-i-use-it?rq=1) and https://en.wikipedia.org/wiki/Recursion? What about industrial programming leads you to believe it'd have any specific relevance to recursion more or less than some other domain? Recursion is a general programming tool that applies to virtually any domain. – ggorlen Aug 31 '21 at 18:26
-
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Sep 05 '21 at 04:48
1 Answers
1
You can encounter recursive calls in many situations, the common ones are:
- to traverse data structures that are recursive in nature (trees, graphs)
- to perform retries of the same function in case of errors
- for numeric calculations if the recursive notation brings clarity (if performance is critical it's pretty common to turn them into loops, unless you use language optimized to do tail calls)

nazgul
- 449
- 1
- 4
- 10
-
1I don't think that recursion has a common use in retries of erroneous function, at least I've never seen a recursion used for retries – mangusta Aug 31 '21 at 18:10
-
depends on the style, using loop is for sure more common, but in this case you could have code like: `connect() { if (!try_connect()) connect(); ... do stuff... } ` – nazgul Aug 31 '21 at 18:21
-
1If you have too many retries, the stack will overflow in languages that don't support tail recursion. Some recursive data structures are linear, like linked lists, and are therefore not well-suited to recursion in languages that don't optimize recursion: the typical data structure won't fit in the call stack. – ggorlen Aug 31 '21 at 18:25