Recursion, iteration loop, iterate

Recursive and iterative cycle is a
distinction between "recursion" and "iterative" are as follows:

1, the basic concept of recursion: programming skills program that calls itself recursively called, is a function that calls itself a function directly in its definition. or indirectly calls itself a way, it is usually a large, complex problem into a problem similar to the original smaller problem to solve, can greatly reduce the amount of code that a limited ability recursive statement to define the object of infinite sets.

2, the iteration: the use of a new variable of the original value of the estimated value of a variable is if the recursive calls itself, it is an iterative A constantly call B..

3, there must be recursive iterations, but not necessarily recursive iterations, most are interchangeable. Iteration can not recursive, recursive call function, a waste of space, Recursion too deep and likely to cause a stack overflow.

 

Traversal is sequentially for each element in the collection and make do only one visit.

Guess you like

Origin www.cnblogs.com/agnesFlower/p/12542529.html