You are on page 1of 1

In accordance with given scenario, Loops are the best which we can option to use.

As we have limited memory available, loops are perfect option because internally for every
recursion (i.e.) for every return value a new stack is created. So, a lot of memory is wasted if we
have many recursion calls.

Recursion repeatedly invokes the mechanism, and consequently the overhead, of method calls.
This can be expensive in both processor time and memory space while loops don't as they use
iteration.

on the other hand In loops, we define set of iterations based on given conditions.

(for example for i >10 when the given condition is satisfied it executes the set of instructions in
the loop when it finishes execution then the instance created for i >10 does not exist in memory
because all instances created are destroyed where as in recursion instances are kept as they
enable backtracking.)

So this proves that memory wise Loops are efficient as loops instances are cleared after every
iterations. Hence, in applications where memory is less, loops are optimal choice and when
memory is abundant and backtracking is required then recursion should be used.

You might also like