+ 3

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

12th Jan 2020, 5:24 PM
Soyaib Zihad
Soyaib Zihad - avatar
10 Respostas
+ 12
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);
12th Jan 2020, 5:51 PM
John Wells
John Wells - avatar
+ 4
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.
12th Jan 2020, 6:07 PM
John Wells
John Wells - avatar
+ 2
Thank Mr. john Wells
12th Jan 2020, 6:00 PM
Soyaib Zihad
Soyaib Zihad - avatar
+ 2
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/
12th Jan 2020, 6:06 PM
Zerokles
Zerokles - avatar
+ 2
This is a recursive challenge I made. https://www.sololearn.com/post/1848
12th Jan 2020, 6:11 PM
John Wells
John Wells - avatar
+ 2
https://www.sololearn.com/post/206034/?ref=app
12th Jan 2020, 6:20 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
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.
12th Jan 2020, 7:35 PM
HonFu
HonFu - avatar
+ 2
If you want deeply learn recursion then you must learn from geek for geeks.
14th Jan 2020, 12:00 PM
Pravesh Maurya
Pravesh Maurya - avatar
+ 1
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.
14th Jan 2020, 1:25 AM
Doulkom Adama
Doulkom Adama - avatar
0
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
12th Jan 2020, 7:42 PM
monica
monica - avatar