Tuesday, 4 February 2014
Late Week 4: Recursion
In week 4 we focused on the powerful concept of recursion. Recursion allows us to solve larger problems by breaking it down into smaller problems known as the base case. In programming we have functions that calls itself in order to recursively handle each instance of the situation. In class for example we had a problem that dealt with finding the maximum number of list and possibly a nested list. We would check each element of the list to check whether the type was a list or an integer. If it was a list, then the function would do a recursive call and run the function again doing the same procedure. If the element is not a list, we would append the number to a new list through list comprehension. Furthermore we can also see that this is our base case which will help us avoid any possibility of an infinite recursion call.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment