O
Ohmu
Hi!
Is there a faster and less memory eating way to do things than recursion?
Ohmu
Is there a faster and less memory eating way to do things than recursion?
Ohmu
Is there a faster and less memory eating way to do things than recursion?
Ohmu said:Hi!
Is there a faster and less memory eating way to do things than recursion?
Ohmu
Ivan said:Typically yes, in C/C++ as in other procedural languages.
but it depends on the specific algorithm you want to derecursify.
Sometimes a recursive call can be replaced by a simple loop.
Sometimes you need some type of cache/buffer/queue, which
makes the implementation more complicated.
Maybe you'll want to post a specific example...
hth
Bruce said:Sounds a lot like the 8 queens problem. Is that what it is? If so, just
say so instead of being evasive. Or are you wanting homework done for you?
Ohmu said:Is there a faster and less memory eating way to do things than recursion?
Ohmu said:Well.. the code I have is tooo messy... I just try to explain what it
does...
There are some squares for example 6x7 and the recursion tryes to find
every possible combination of "x" that can be there without being on
each other way(only one in one column and one row and one in
diagonals)... so the function calls itself where it finds a spot where
the "x" can be put, and so every time until the size of the squares
are reached... but for this 6x7 squares the function calls it self
about 300-600 times.. it eats lot of memory and when the squares are
bigger it takes huge amount of time and loads(in MB) of memory...
E. Robert Tisdale said:Ohmu said:Is there a faster and less memory eating way to do things than recursion?
No.
A *good* optimizing C++ compiler will "flatten"
a recursive [inline] function call automatically
if it really can realize an advantage by doing so.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.