2015年4月6日星期一

Week 12: Look back

LOOK BACK


I think it is more helpful for me to write about the knowledge about CSC148 other than the express my emotions about the class ends.

In the beginning we learnt about Class and we did the A1of subtract square to practice class method.

Then we did many excise in lab about class and list. The list is getting hard, and we learnt about recursion.

In the beginning I think recursion is useless but then I find I always need to use recursion to write the function in Tree.

Yes, tree. We learnt some type of tree, such as binary tree. I think tree is interesting but hard as well. I spent most of my time in linked list and binary tree, but I did not get good score in exam 2. I think I still need to do more excises.

I feel the most helpful things along this course is the material in lab.

Week 11: Agree or disagree with my earlier self

 Agree or disagree with my earlier self

I took about half an hour read about the slog I posted before. I can feel I am making progress as time fly. And I viewed some of my classmates' slog, they are all making progress.


However, I feel I still need to work harder, since I did not do good in the 2 exams so did lab. I thought I did my best, but I didn't. I was lazy and even skipped few classes. I should be more hardworking!

In the slog I wrote before, I could see I was trying to conclude some trick of writing code. But after I received my grade of my exam 2, I was really disappointed about my score. There's no trick of writing code other than hardworking.

I agree some of my points in the earlier slog, but I hope I could do more works. 



2015年4月2日星期四

Week 10: Impression about week 9

Impression about week 9(EXAM)

Although week if the exam2 week(exam was extremely hard), in the morning lecture, we still learnt something about Binary Tree node:


The above is the general form of the BTNode. Unlike what we learnt a few weeks before(LLNode), in the BTNode, there are left_node and right_node. The left_node is less than the parent.value, and the right_node is larger than the parent.value.

The following is the basic code of BTNode:

class BTNode:
    '''Binary Tree node.'''

    def __init__(self, data, left=None, right=None):
        ''' (BTNode, object, BTNode, BTNode) -> NoneType

        Create BTNode (self) with data and children left and right.
        '''
        self.data, self.left, self.right = data, left, right

I was confused at first about the Binary tree, but then I figure out that the most left is the node with the smallest value of data, and the right most node has the largest value of data.

There are also some things I learnt about writing code of BTNode:

1. in the beginning of the code, we need to write a if condition of node is empty.
2. in writing the code, it is easier to consider the node.left and node.right as two parts.
3.list method is a good method to use when doing delete or insert.

I still think BTNode is hard, and I hope I could do better in learning materials and also do good in the final exam.

Week 9: Impressions of week 8 -Linked List-

-Linked List-
This week I learnt about linked list. This is a common method of storying data. In linked list, there is a class called Node. The data is connected by node; the first node will linked to the second node. Linked list is a very useful method.

As objects/ nodes with a value, those objects/nodes also have a reference to the other similar objects. The basic structure is:

(12)()---->(99)()---->(37)()--->()




The structure of node class is:

class LLNode:

     """Node to be used in linked list
     nxt: LLNode -- next node
                               None iff we're at end of list
     value: object --data for current node
     """
   
     def __init__(self, value, nxt=None):
          """(LLNnde, object LLNode) ->NoneType

          Creat LLNode (self) with data value and successor nxt.
          """
          self.value, self.nxt = value, nxt

There are also front and back in code, which helped us to find the front and end of the list.

I learnt many helpful code from class, such as:

                                  cur_node  = self. front
                                  cur_node = cur_node.nxt

By using the code I can add or delete the end node. Besides the last node, former last node, back, size, possibly front could all changed by using the method.



I noticed from the lab that when writing code of linked list, it is easy for me to make a copy of the list first, since if any node changed the following data could not be find.

Week 8 - Impressions of Week 7

Impressions of Week 7

This week 7 is also about BTNode. The things in lab is hard but fun. In the lab we need to write functions to find:

1.height

2.node with maximum data
3.insert data
4.whether tree contains a specific value
5.whether tree rooted at node contains value
6.delete node that has the specific data
7.find node with a specific data
8. the result of evaluate
9.the result of parentesize
10.the list between a specific value of start and a specific value of end
11.the list of internal between a specific value of start and a specific value of end
12.the lis of data in the longest path
13.check a node is a leaf or not
14.preorder_visit
15.postorder_visit

Every thing is hard and had taken me lots of time to think and write about, but after I finished the lab I feel I won a war: BTNode is not as hard as before. I could easily find the height by using function like:


return 1 + max(height(node.left), height(node.right)) if node else 0

And easily find the hardest part -- parentezise by using:


if is_leaf(b):
        return str(b.data)
    else:
        # produce the string expression, then evaluate it
        return '({}{}{})'.format(parenthesize(b.left), str(b.data), parenthesize(b.right))

I think I could handle the BTNode easier than before.

Week 7 - Summary of Abstract Data Type

Summary of Abstract Data Type

In week 6, we learnt about abstract data Type -- Binary Search Tree:

class BTNode:
    '''Binary Tree node.'''

    def __init__(self, data, left=None, right=None):
        ''' (BTNode, object, BTNode, BTNode) -> NoneType

        Create BTNode (self) with data and children left and right.
        '''
        self.data, self.left, self.right = data, left, right

    def __eq__(self, other):
        ''' (BTNode, object) -> bool

        Return whether BTNode (self) is equivalent to other.

        >>> BTNode(7).__eq__('seven')
        False
        >>> b1 = BTNode(7, BTNode(5))
        >>> b1.__eq__(BTNode(7, BTNode(5), None))
        True
        '''
        return (type(self) == type(other) and
                self.data == other.data and
                (self.left, self.right) == (other.left, other.right))

The structure of BST is interesting:

The the root has two child, left node is less than the root, and the right node is larger than the root. The nodes that have child is called node.data, and child is called node.child. hight of the tree in the above picture is 4, since there are four level. There is also a recursive definition since the subtree is preordered.

The cod of the tree is write in the structure of: node.data, node.left, node. right. In node.left and node.right there could also contain a node.data structure. 

Anyway, I only learnt about the basic things about tree, but it is an interesting type of abstract data type.

Week 6: Summary of Object-Oriented Programming concepts

Object-Oriented Programming concepts

"Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which are data structures that contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. "

The above is the definition of Object-Oriented Programming from wiki. In week 6, we finished the tippy using minimax method. The user could play tippy in python interface. In the game which I designed, the user could choose the range of graph that he or she wanted to play. Computer is the opponent, which will find the best option that could defense and lead to winning. 

The followings are the some structure of minimax:





It is very interesting, when writing the Tippy program, we need to find all situation that a tippy could put on the board:

  ++                ++           +               +
     ++          ++              ++          ++
                                         +         +
The computer need to use minimax method to choose the best place to put + on the board among all the options. And we also need to make sure the program can tell the user the result: win, lost or tie.

There are many details we need to think about, and we need to play the game for a while in order to make sure player could understand the game easily, and exclude any bugs.