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.

Saturday, 22 February 2014

Week 6

This week we continued learning about recursion. In the lab, we have worked on coding dot product and matrix vector product. During the process, we were asked to write a code without using the list comprehension. Mostly, our task was to simply write a code the uses for loop (in some cases, multiple loops) . The task was relatively easy compared to previous labs. The difficult job assigned was the A1, the Tower of Hanoi assignment. Personally, I spent most of my time with my partner debugging TOAHModel and discussing over and over about tour.py. In order to to approach the part 5 to part 6 of the assignment which required our concrete understanding of how recursion works, we first traced the simple cases of the function that moves cheeses recursively. After then we were able to get a clue how to apply three_stool method into four_stool method. Since my learning style was passive during the lectures, I had to revisit lecture notes and review it. One good tips I can suggest for future reference is to try to trace as many example cases as possible, from the most simple to a bit complicated ones that suits into the recursive function, before actually writing the code.

Friday, 7 February 2014

Week5

During this week, we continued dealing with the recursive code, and also we were introduced to the new topic, how python's scope operate and look for names/values. First, at the beginning of the Monday's lecture, Professor. Heap briefly mentioned the strategy we can implement for the tower of hanoi's code. By understanding the the recursive structure of the code used to move cheeses (code for the tower of hanoi), it gave me a good start-off point in completing the assignment. In the Week5 labs, my partner and I again worked on tracing/creating recursive code. Mainly, we wrote the body of the function SearchList function. Since it was the first trial in my coding experience to write recursive function, I struggled with writing the base case. On top of the course material discussed today, supplemental readings on the course website was useful for my lab partner and I to implement the function. As well, communicating with other classmate also helped us see the variation in coding. One tip I would recommend for future reference is to remember creating a simple test cases before moving on to defining the function.