Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Recusion
Index -> General Discussion
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
iFlexion




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

Can someone explain recursion to me?
Sponsor
Sponsor
Sponsor
sponsor
iFlexion




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

i meant recursion in title sorry
Insectoid




PostPosted: 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




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

tysm!
Display posts from previous:   
   Index -> General Discussion
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: