The concept of recursion is somewhat novel, but quite simple once grasped. While I initially had difficulty conceptualizing recursion at an intuitive level, sorting the concept into two specific situations: a base case, and a recursive step, solidified my understanding. Recursion in this way is quite similar to proof by induction in mathematics, where instead of a recursive step, there is the inductive step, and where the process starts instead of ending at a specific base case.
I appreciate recursion however, not through its novelty, but its actual use. Particularly, printing the contents of a binary tree with recursion displays why the ability to use certain methods/functions an unspecified number of times is so powerful. For this reason, the base condition of a recursive function is a lot like a while loop. One who employs recursion into code plans a condition for which the recursive function to end in a certain way and implements it as the base case. Essentially, any time I wish to do anything with an object that is repetitive in structure, particularly involving nodes, I can use recursion.
No comments:
Post a Comment