16.2 Basic Recursive Techniques


16.2 Basic Recursive Techniques

Recursion is often associated with a method. A recursive method calls itself from within its own body. A recursive operation achieves exactly what an operation with iterations achieves. In principle, any problem that can be solved recursively can also be solved iteratively. With iteration, a set of instructions is executed repeatedly until some terminating condition has been satisfied. Similarly with recursion, a set of instructions, most likely a part of a method, is invoked repeatedly unless some terminating condition has been satisfied.

A recursive definition of a function consists of two parts:

  1. One or more base cases define the terminating conditions. In this part, the value returned by the function is specified by one or more values of the arguments.

  2. One or more recursive cases. In this part, the value returned by the function depends on the value of the arguments and the previous value returned by the function.




Object-Oriented Programming(c) From Problem Solving to Java
Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)
ISBN: 1584502878
EAN: 2147483647
Year: 2005
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net