Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Recusion
Author Message
iFlexion

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

Can someone explain recursion to me?

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: Sat May 30, 2020 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.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 5 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: