At first glance, recursion looks like a difficult concept, however after some practice tracing it, it isn't too hard. A function that calls upon it's self within it's self is an example of the recursion we have done in CSC148. I found this to be quite useful, specially for calculating a sum in a list of lists. If you don't know the size of the list containing many other variable size of lists, and you don't want to have a loop and an if statement to accumulate the sum, you can just use a simple recursive code. One that would add elements together in a list and return the sum.
No comments:
Post a Comment