Post Reply 
(12C Platinum) Successive Discounts
12-24-2018, 06:32 AM (This post was last modified: 12-24-2018 06:47 AM by Gamo.)
Post: #9
RE: (12C Platinum) Successive Discounts
The meaning between Iteration and Recursion is very interesting to find out.

So I did some searching around the web and here what they said the different and explanation.


Iteration and Recursion are key Computer Science techniques used in creating algorithms and developing software.

In simple terms, an iterative function is one that loops to repeat some part of the code, and a recursive function is one that calls itself again to repeat the code.
Using a simple for loop to display the numbers from one to ten is an iterative process.
Examples of simple recursive processes aren't easy to find, but creating a school timetable by rearranging the lessons, or solving the Eight Queens Problem are common examples.


The old recruiting practice says, "Never hire a developer who computes the factorial using Recursion". Recursion is often used without considering alternatives before using it.
Though it is true that recursive solution is often more elegant and easier to spot than the iterative solution, one should take care not to abuse it.
Complex Recursion that is hard to understand should probably be considered a "bad smell" in the code and a good candidate to be replaced with Iteration
(usually in combination with some other Refactorings).
Moreover, iterative solutions are usually more efficient than recursive solutions as they don't incur the overhead of the multiple method calls.

We use Recursion when we have to perform a complex task that can be broken into the several subtasks.
Recursion is implemented as a method that calls itself to solve subtasks.
During the recursive call the values of the local fields of the method are placed on the method stack until the subtask performed by a recursive call is completed.
Thus, whenever recursive method is called, local fields are put on the method stack and used again after the recursive call is completed.
The general approach to Refactoring could probably be to implement the alternative Stack that "simulates" the method stack where the local fields could be placed
(the java.util.Stack class is a good candidate for this job).


Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
(12C Platinum) Successive Discounts - Gamo - 12-22-2018, 05:07 AM
RE: (12C Platinum) Successive Discounts - Gamo - 12-24-2018 06:32 AM

User(s) browsing this thread: 1 Guest(s)