Sunday, April 5, 2015

Last impressions

Over the course of this term, I learned many new things. First of all, I learned more about classes and got to know two new types of abstract data structure, namely Stack and Queue. I learned to write different methods for the classes, such as __eq__, __repr__, __str__ etc.. I found out that classes can build on a preexisting class, and adopt all of its features using inheritance. This increases efficiency because it reduces the need to write duplicate code, if one or more classes have common features with another class.
I also learned about tracing and writing functions. Recursion was very hard for me in the beginning because I tend to lose track of what the code does when it calls itself again without finishing the initial call. Luckily, I had help from my friends and Prof. Danny. They traced a couple functions with me and cleared a lot of my confusions. Writing recursive functions was also fairly challenging. I learned that to write them, I need to consider what is the simplest case that does not need recursion (which is the base case), and then ensemble these simple pieces of information together that returns a desired result.
Trees (and binary trees) are applications of recursion. Trees have a recursive nature in which one children can branch off and have many children and so on. I had a lot of practice in using recursion during tutorials and assignments, in which many tasks involve finding how many internal nodes there are, or returning particular values at the leave nodes. Linked lists are kind of like trees in which they also have nodes, but are ordered in a linear fashion. In beginning, I was confused of why there are two classes for linked lists, and what instance variables to refer to in writing code for them. But later I learned that, linked lists involve a collection of nodes. Hence, one class is specifically one node, and another class is a wrapper that stores the collection. Trees and linked lists are two new data structures that I learned in this term, which I think will be very beneficial in solving problems in the future.
Towards the end of the term, csc148 had a lot of overlaps with csc165. I learned more about algorithm's running time, worst case running time, and asymptotic representations of these running time. I learned that running time varies depending on the size of input (n) and I saw examples of code that is big-O of n, n^2, n^3 and lg(n). These notations allow us to better analyze and compare the efficiency of different codes, which is very helpful in terms of choosing the better option. If there are more options available for achieving a same task, but one has a running time in O(n^2) while another has O(lg n), then the latter one is much of efficient for users, because when input size n gets large, n^2 is huge and takes a long time, but lg n is much faster. 
This term taught me a lot of useful techniques, like tracing functions, writing recursion and many new data structures, like Stack, Tree etc. They combine to prepare me to be a more efficient problem solver. Although I had challenges along the way, csc148 was certainly useful and heuristic, as it gave me practices on logical reasoning and problem solving.

impressions of week 9

In week 9, I learned more techniques on choosing test cases and tracing function calls. In lectures, Prof. Danny showed us one possible solution to minimax. When I was working on assignment 2, writing functions to make minimax work was the most challenging task. I thought that every game state is a node, but didn't know how to return a move that leads a winning state. In lecture, I learned that tuple is a choice of good data structure that can be used to link a move with a state. An initial state have a list of possible moves, and each of the moves can lead to another game state, and so on. Because of the nature of the data, recursion is the suitable strategy to return what initial move can lead to a final winning state (if there is one). I learned that recursion can be applied to each of the moves, until the very end, where a player wins. That final game state would generate a score of +1 for the player who won. Once the leave nodes are calculated with a score,  recursion can trace back the path that led there, thereby suggesting an initial move.
On top of learning the algorithm on solving minimax, I also learned in class of how to trace function calls. For example, the following program, when run with python, would generate a value of 12. However, the process of reaching there involves many steps. I learned that python prioritizes an input value over another variable value, even though they may have the same variable name. When h(1) is called, the function h(N) is called, with N=1, but not 5, even though that the variable N is given the value 5 in the beginning. Furthermore, because h(N) involves a nested call for both functions g and f, each time the input N is changed according to the value returned from the nested call.
Tracing calls like this seems really easy and basic, but it is a very good practice which helps programmers to follow through the code and see what the code does at each step This can be very beneficial if in the future that we ever have to write complicated programs that involve many variables.