Uses of Recursive functions? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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??

5th Jun 2019, 7:02 PM
Aman 777
Aman 777 - avatar
4 Answers
5th Jun 2019, 7:14 PM
Trigger
Trigger - avatar
+ 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.
5th Jun 2019, 7:30 PM
AZTECCO
AZTECCO - avatar
+ 2
Makes complicated code simpler Recursive algorithm helps in code reduce reusability improve performance
6th Jun 2019, 8:22 AM
sree harsha
sree harsha - avatar
+ 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)
5th Jun 2019, 7:39 PM
Vlad Serbu
Vlad Serbu - avatar