File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes Recursion on Android Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Recursion on Android" Watch "Recursion on Android" New topic
Author

Recursion on Android

Ali Khalfan
Ranch Hand

Joined: Nov 03, 2007
Posts: 126
Hi,

Don't know if anyone ever considered this, but is implementing recusion on android ever a good idea? I know recursion is something that should be avoided whenever possible, but the algorithm I'd like to implement will be a lot easier with recursion.

I was just worried about the stack in general.


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41125
    
  45
I know recursion is something that should be avoided whenever possible

This is just wrong, plain and simple. There's nothing bad about recursion in itself. If the algorithm is recursive (like QuickSort), then, by all means, implement it recursively. Looking at code that implements QuickSort without recursion is just nasty - don't do that! I have held forth on this subject before, you should read those topics for more information: http://www.coderanch.com/t/422207/Programming/Why-recursion and http://www.coderanch.com/t/5200/Cattle-Drive/Recursion. There are big differences between linear recursion (might be OK) and tree recursion (probably bad, unless there are definite limits on tree growth).

I don't think that there's anything Android-specific about whether or not to use recursion - yes, mobile devices tend to have less memory available, but if a recursion takes up that much memory it's probably inappropriate to use anyway.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Recursion on Android
 
Similar Threads
Tech Word Game
Printing a String object without using loop
How to enforce android to choose between the installed browsers while opening a link
Droid X vs I Phone 4
Factorial