Sunday, March 22, 2015

Week 10: Impression of week 9 and week 10

In week 8, we have discussed about what is a wrapper class and the function of it. To understand the concept of wrapper class well, we also have talked  about how to use a wrapper function in real class writing, for instance, writing a LinkedList class, which is a wrapper function of LLNode classes and understanding how walk along in it. 

In week 9, we make a further discussion about wrapper class, which is how to write a seen a BTNode as a wrapper class and rewrite several basic functions in it.



In week 10, Danny helped us analyzing strategies of our assignment 2 and introduced some new ideas to make our assignment 3 into a further step, which is help computer decreasing useless consideration and repeated steps.  The first step, which I think it's useful, for us is to understand the function of strategy and make it delicate is to draw a tree of whole possible moves of subtract square game between two players. After drawing whole tree of possible moves in subtract square game, I found that there are some repeated game state during this game which will come to a fixed ending for each of two players,which means we can tell computer do not run these repetitive so that it can save run times of the class.

Saturday, March 14, 2015

Week 9: Linked List - impression of week 8

I have learned a new class which is about write linked list.

Although the linked list is called as a list, it is not a real list as what we have learned before. What I think that a list should looks like is it should be with two square brackets. However, we can still view linked list as a special list without any square brackets. The linked lists are lists made up of an item(or value) and a sub-list, this sub-list is also a linked list which is made up of its own value and a sub-sublist and so on. In addition, we can view linked lists as a node with a value and a reference to other objects which may also be a node of linked list.


A linked list is a linear sequence of nodes. However, in this case, we pick the second idea of linked list. So we defined two class to build a wrapper class of a LLNode class and a LinkedList class. In order to track and view linked list well, we keep a reference to the front (we may called self.front in LLNode)of a sequence. We call the tail item of a linked list back. 



In Linkedlist, we may need to make some changes of items in LLNode. That's to say, we will walk along a list. To find what we are looking for and make change of it, we are required to record previous part and current part of node which means waling along a list with two references.

Saturday, March 7, 2015

WEEK 8: Impression of Week 7

On week 7, I've learned what is a Tree class and a binary tree which is a type of tree with only two branching factors. A binary tree usually has children called left and right child.

In the lecture, we use a BTNode to study a binary tree. This BTNode class is a binary tree that left children in each node(can be viewed as a parent of a subtree) is smaller than right children in that node. What I need to do to understand BTNode first is to understand the functions in the basic Tree class.


contains(t,v): is used to determined whether the value v is in the tree t, or the tree t may has no children and whether value v is eaqual to tree t itself.

height(t): is used to tell users the height of total tree. What we should know is that the value of height of a tree is equal to number of branches plus one.

descendents_from_list(t, L, arity): is to populate tree t's descendents from L. Arity is a integer which tell users the number of children of each level node.

In BTnode class, we learned how wo add children or new node in Tree. Visiting each node and do something at each node is called traversal. In-order traversal is to visit a node between visiting its two children.

To finish lab06, we need to know the job of is_leaf(node) function and how to use it. is_leaf(node) function is a helper function to help each function to determine whether Tree has children or not. If the tree node is not a leaf, we can use recursion to help each function run to get final result.


Sunday, March 1, 2015

Week 7 Summary of Recursion

I've learned and are using both 'For' loops and 'While' loops in some functions to solve several problems that have finite steps. However, it's hard to design functions which have infinite steps and it is also hard for us to make an accurate extimation on how many steps the functions would proceed. The professor introduced us a much easier way to simplify complex functions from a huge size to a delicate structure which make uses understand easily and make computer run programs much faster. That's recursion.

As what I wrote in slog of last week, "when a function calls itself, we say that is a recursive.", which means this function use recursion strategy in itself.

At the beginning of the lecture of recursion, we've learned how to understand recursive data structure. A recursive data stracure always contains some substrures and itself.


Adding the statement into the functions which make functions call themselves calls recursive call. A feasible recursive call contains a base case and other cases and also a case make function recall itself. It's significantly important to built a base case in funtion. Because missing a basic case, which is similar as setting conditions for 'while' loops,will result in infinite loops of functions.

In recent lectures, I've learned how to use recursion in real problems such as Tree classes.

Recursion is a good strategy to solve problems like class Tree. When we are facing problems like "subitems contain subitems contain subitems....."(this is a recursive data structure), we use recursion which is based on a solid base case to recall infinite times of problems themselves untill we operate whole possible processes in structure.

What I think is a challenge for me is how to determine a correct and precise position to put my recursion. It's easily for my to forget put recursion in function and put correct recursion in 'return'. What should I do in future to overcome these challenge is to do more extra exercise so that I can master this strategy more easily.