(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
 Gamo Senior Member Posts: 706 Joined: Dec 2016
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).

--------------------------------------------------

Gamo
 « Next Oldest | Next Newest »

 Messages In This Thread (12C Platinum) Successive Discounts - Gamo - 12-22-2018, 05:07 AM RE: (12C Platinum) Successive Discounts - Dieter - 12-22-2018, 09:07 AM RE: (12C Platinum) Successive Discounts - Werner - 12-23-2018, 09:11 AM RE: (12C Platinum) Successive Discounts - Dieter - 12-23-2018, 09:33 AM RE: (12C Platinum) Successive Discounts - Gamo - 12-23-2018, 03:05 PM RE: (12C Platinum) Successive Discounts - SlideRule - 12-23-2018, 03:13 PM RE: (12C Platinum) Successive Discounts - Dieter - 12-23-2018, 06:16 PM RE: (12C Platinum) Successive Discounts - SlideRule - 12-23-2018, 07:45 PM RE: (12C Platinum) Successive Discounts - Gamo - 12-24-2018 06:32 AM RE: (12C Platinum) Successive Discounts - Thomas Klemm - 12-24-2018, 11:25 AM RE: (12C Platinum) Successive Discounts - Albert Chan - 12-24-2018, 12:52 PM

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