Thursday, 27 February 2014
Week 7
Recursion, by definition, refers to "...a method where a solution to a problem depends on solutions to smaller instances of the same problem" (google dictionary). For the last several weeks, including the week 7, our class dealt with the coding examples and problems involving recursion. In the past, the professor have given us a visual demonstration of recursion through turtle example. When visualized, we were able to see a pattern where the the large picture consists of smaller pictures in a recursive pattern. A tree with three branches(first branches from the root) that consists of three branches in each end of the first three branches, and another set of three branch from the previous branch, etc... is an example of a recursive pattern. In terms of the practical coding, we learned list comprehension is useful to code recursive functions. The common patterns of recursive coding I have seen is as follows: f(x) for item in object if (condition) else (base case). Depending on the situation, there was variation in where to put the list comprehension in the structure given above. As such, often times I have encountered the cases where the base case was given as the else clause of the list comprehension and normal cases, the one that uses recursive call f(x), written at the front with its if clause attached. One of the challenging task assigned in regards of this topic was to come up with the right condition statement. The latest topic discussed in week 7 was about the linked list and the Lab 6 was indeed about linked list. The task given to us was to insert and delete item from a tree (of a class other than list). Although the linked list is difficult to follow, so far, we have only dealt with tree that are of arity 1, branching factor 1. Thus, we were able to draw a parallel between the tree and a sequence of list. In summary, week 7 material was continuation of recursion, linked list; the most important information to pick up from the lecture was how to implement a functions that can modify the existing list.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment