Saturday, 28 February 2015

Recurring Recursion

As the hibernation/reading week ends, we continue to learn about recursion, but this time in a different class with a generic tree design called BTNode, allowing the process of recursion methods to be more visual.
Example of a recursive tree
Recall the definition of recursion as “defining something in terms of itself” usually at some smaller scale, perhaps multiple times, to achieve your objective. We can trace the steps of the call by making a diagram as this helps us with not only seeing how the parent and leave functions run, but also be how and in what order the valid codes are calculated. In evaluate method, the return result is the value after being calculated by the __init__ and __str___ provided in the tree. The simplest example of recursion in a tree is when the node is a leaf, which would involve another method in the class.

Definitions:

Data Structure: The organization of data for the purpose of making it easier to use.

Recursive call: The statement inside the function definition in which the function calls itself.

Recursion: The process of calling a function that is already executing

Recursion definition: A definition which defines something in terms of itself, To be useful it must contain a base case that is not recursive. Recursive definitions often provide a easier way to express complex data structures.

Recursive call: The statement that calls an already executing function. 

Base case: A branch of conditional statement in a recursive function that does not give rise to further recursive calls, not having a base case will result ion infinite recursion.

Infinite recursion: A function that calls itself recursively without ever reaching any base case. Eventually, it will cause a run time error.


Source: lecture notes and wikipedia

No comments:

Post a Comment