Cuttings: Recursion, Succinctly Put Recursion, Succinctly Put | Cuttings
Things of interest.


 
December 14, 2018

Recursion, Succinctly Put


And then there were three.

The rules of recursion are so succinctly stated here. From /r/learnpython:

There are 3 rules for recursion:

  1. A recursive algorithm must have a base case.
  2. A recursive algorithm must change its state and move toward the base case.
  3. A recursive algorithm must call itself, recursively.

A base case just means that it has an end point, something to stop it looping infinitely, such as when a particular variable reaches zero.

Changing its state means that through each iteration it gets closer to this variable.

Calling itself just means that you call the function that you’re currently in with this new data to pass in.



 

 
© 1997 - 2018 / Info