My understanding of recursion in the first few weeks was very vague. I didn't understand how exactly recursion works, because I thought recursion was a complex algorithm. From my understanding before recursion was a function that calls itself, but everything else was hard to understand. When I had to understand a recursion I needed to trace it or make an guess.
My current understanding of recursion is a function that has a base case that does not use recursion and another case that use recursion to approach the base case (recursive case). The base case is case that has no more sub-cases. For example, leaf node in a tree would be base case (since it has no children) and internal node would be the recursive case (since it has children and its children might be the base case). To make recursion work the recursive case must be getting closer to the base case, for example internal node is getting close to leaf node because eventually internal node's children will be leaf node if the tree is not infinitely big. Otherwise recursion will result in error because it's going to recurse infinitely.
No comments:
Post a Comment