+ 2
Uses of Recursive functions?
What are main ‘applications’ of recursive functions, practically? Recently I’ve been learning about functions and parameters and came across recursive functions. Other than calculating factorials is it used often??
4 Respuestas
+ 1
Well, it has it's uses...but I cant say I often use recursive functions. The only time I really use them is when working with a factorial of a number (though In sure guys in the business might use it for more)
https://code.sololearn.com/ct65XMNT1ok9/?ref=app
https://code.sololearn.com/cMvkcWhVYtby/?ref=app
https://code.sololearn.com/c3NCbOEFnerg/?ref=app
https://code.sololearn.com/c4eLKogGLN3J/?ref=app
https://code.sololearn.com/cR5vZ2Im19DB/?ref=app
https://code.sololearn.com/clD4HX3KpOHx/?ref=app
https://code.sololearn.com/cZ0ljNOI3SOq/?ref=app
+ 4
In real life coding recursion is used in c++ Template Meta Programming
TMP reach Turing completeness, making it a programming language, with recursion which is the only way to make loops.
In normal programming it is not recommended to use recursion due to low readability and complexity, although you can use it in every loop situation if you want.
+ 2
Makes complicated code simpler
Recursive algorithm helps in code reduce reusability improve performance
+ 1
You probably shouldn't use it for factorials, as it's slower than a for loop.
It is used however in backtracking, and other similar algorithms. Generally, when you have a graph-like structure, it's very convenient.
A file system is a graph like structure. Here's an example that does something for every file in a directory, including the files in all subdirectories (pseudo code):
function doSomethingForEveryFile(dir)
for each file in dir
if isADirectory(file)
doSomethingForEveryFile(file)
else
doSomething(file)