I need to learn recursion.. Can u help me plz whom or what should I follow? | SoloLearn: Learn to code for FREE!


I need to learn recursion.. Can u help me plz whom or what should I follow?

1/12/2020 5:24:18 PM

Soyaib Zihad

10 Answers

New Answer


Recursion is easy. Any loop can be turned into a recursive function. The body of the loop becomes the function body. The condition of the loop becomes the exit condition. for (int i = 0; i < 11; i++) cout << i << endl; Becomes: void loop(int i) { if (i < 11) { cout << i << endl; loop(i+1); } } loop(0);


Note that the reverse is true. All recursive functions can be turned into a loop. There are algorithms that are very complex as loops, but trivial with recursion. Others, the reverse is true. Once you are comfortable with recursion, you should always pick the least complex code. Until then, force yourself to replace all loops with recursion.


Thank Mr. john Wells


Recursion involves functions that call themselves. One common example that you can try out is the factorial function. There are lessons regarding recursion under some of the programming language courses here on Sololearn (at least for the C and Python 3 courses). As another example, here is a coding challenge you can solve through recursion: https://www.sololearn.com/learn/6768/


This is a recursive challenge I made. https://www.sololearn.com/post/1848




Look over my code list for everything with 'recursive' in the name. I struggled for a while with recursion and did a lot of very simple things with recursion, and I think, this practice helped me to finally get it. You can go for the same tasks, trying to solve them.


If you want deeply learn recursion then you must learn from geek for geeks.


Recursive functions are function that call themselves.For example: int factoriel (int n) { int a; if (n > 1) a=n*factoriel(n-1);//here the factorielle of n is calculated and stored as a value. return a; } hence you must learn about function first.


Recursion is function calls itself and does the same behaviour or action for all the different inputs you give each time as arguments while calling the function and terminating it with a base case