Monday, 3 March 2014

Recursion

After tracing and practice through a couple recursive function, I finally understand how they work. They seems to work in 'layers' (kind of like Inception). This can be demonstrated with the first recursion we did in class, the sum of the nested list. For example, if the nested list is [1,[2,3,[4]]], the function calls itself again if it encounter another list, like going into layers after layers. So recursion is very good with  list within list, or more generally, it is very good for accessing information of an object within another object for our uses purposes. Another example we encounter is Trees, in order to access the information of a tree (its nodes), we can express the leaves of a tree in nested list, which can be access using recursions.

No comments:

Post a Comment