Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Thread Tools Display Modes
Prev Previous Post   Next Post Next
Super Moderator
Status: Offline
Posts: 249
Join Date: Dec 2012
Location: Frosno, Ca
Default Recursion - 01-31-2016, 04:20 PM

In order to forget recursion,you must first forget recursion.
Is a toung in cheek way to remember it.

On the one hand recursion can be an elegant solution to a complex problem while on the other hand, it's execution can be slow and resource intensive (using lot of memory, disk space or both.)

Basically, if you can beappreak a problem's solution into smaller and easier to solve problems, you can use recursion to solve it. At the same time it should probably be made clear that any recursive method can be rewritten in a non-recursive way.
A silly example:
    return(count(int-1)+1) // the call that makes this a recurrence 
    return(0)  // the condition that cause the recursion to end.

So count(3) would result in:
      return count(1)+1
Which would call itself 4 times until the argument was 0 and then begin ending each recursive step back up the call chain returning 0, 1 , 2, and finally 3. Note that while the function is recurring, none of the previous calls can end. This is what uses up resources.

Hope this helped,

Mark Henwood
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Copyright ©2018, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.