Recusion
Author 
Message 
iFlexion

Posted: Tue Nov 12, 2019 11:12 am Post subject: Recusion 


Can someone explain recursion to me? 





Sponsor Sponsor



iFlexion

Posted: Wed Nov 13, 2019 11:24 am Post subject: Re: Recusion 


i meant recursion in title sorry 





Insectoid

Posted: Mon Nov 18, 2019 2:29 pm Post subject: RE:Recusion 


Recursion is basically a function calling itself.
Function a(){
Return a()
}
It's great when your algorithm does the same thing over and over, where a loop would be awkward to code.
Imagine trying to solve a corn maze yourself in real life. Always take a left first, then try going straight, then go right. If you hit a dead end, backtrack to the last intersection and try another direction. But it's a big maze! You can't remember where you've been, how far to backtrack, which paths to take. It's just too much.
Now you're a popular guy with lots of friends, so you invite them along to help you. Everyone gets simple instructions: everyone stands at an intersection. You start at the beginning. Walk to the first intersection and ask that friend, what's down the left trail? He doesn't know so he goes down the left trail and reaches another intersection with another buddy, so the one asks the other, what's down the left trail? And he doesn't know so he goes down the line and sees it's a dead end, backtracks and reports it's a dead end. So next your buddy asks, what's down the middle trail? So he goes to investigate, finds another intersection with another buddy, and the cycle carries on down the chain until somebody finds the exit. That person reports to the guy that asked that the finish line is down the middle trail. The information filters up the line, all the way back to you. So the very first guy you asked can tell you 'take a right turn'. You do, find another intersection, that guy says go right. And you just keep following the instructions until you reach the end.
As a whole, it's a difficult concept to digest. But individually, everyone gets really simple instructions and only needs to keep track of one thing: where is the exit.
The are a lot of problems that for whatever reason are really clumsy to solve with loops, but elegant with recursion. 





iFlexion

Posted: Mon Nov 25, 2019 10:43 am Post subject: RE:Recusion 


tysm! 





raysosher

Posted: Today at 12:36 am Post subject: Re: Recusion 


If you want a task to be performed several times and you do not want to code repeatedly in that case you use reccursion. Using reccursion is very simple, it is just a function that that works again and again just after finishing its job. It calls itself and reworks by itself. You do not need to code several lines to perform several tasks. 






