2015年4月5日星期日

week 11 revisit earlier slogs

1) revisited the slog 'why geeks should write?'.  I am completely agree what I thought. Writing before programming is so important and it helps to organize and structure thoughts.  And when the code is finished, it is easier to track through it.

http://andrewgoupilcsc148.blogspot.ca/2015/04/week-11-revisiting-earlier-slog.html

http://csc148danjessicali.blogspot.ca/

·      “I think it is important for programmers to "write" because it allows us to keep track of our progress. Keeping a SLOG allows us to set goals, take note of ideas we have not fully grasped yet for revisiting, and track backwards to see how we developed certain perspectives.”

Ideas in the slog above are quiet similar with me, and those slogs helped me lot. Reading other slogs helps me to understand the course concepts, Some ideas in the course are hard to accept if I never experienced before, but through slogs, I can understand them easily because some concepts which are explained by students is easy to read.

2) For recursion in tree structure, I am quiet confident with myself through lots of practices.

week 10

week 9

In this week, we are introduced a new tree structure, linked list tree.


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

Unfortunatly, because of the strike, we didn't have the extra help to guide us to the right direction especially that it is a new concept. The lab was not too bad, and by reading through other slogs, the concepts of LLNode is not big deal for me. But I still need to practice the labs. More practice needs to be done with all the methods given in this lab.

week 8

In this week, we are introduced binary tree nodes. And I have found that tree traversals are quiet interesting. Basically, tree traversals is the concept of order of visiting node in trees.

preorder
In a preorder traversal, we visit the root node first, then recursively do a preorder traversal of the left subtree, followed by a recursive preorder traversal of the right subtree.

postorder
In a postorder traversal, we recursively do a postorder traversal of the left subtree and the right subtree followed by a visit to the root node.

inorder
In an inorder traversal, we recursively do an inorder traversal on the left subtree, visit the root node, and finally do a recursive inorder traversal of the right subtree

         1
        / \
       /   \
      /     \
     2       3
    / \     /
   4   5   6
  /       / \
 7       8   9
preorder:    1 2 4 7 5 3 6 8 9
inorder:     7 4 2 5 1 8 6 9 3
postorder:   7 4 5 2 8 9 6 3 1

week 6

summary of Object-Oriented Programming concepts

Object-Oriented Programming is a language model that uses “objects”, which are instances of classes. An object is an abstract data type, and it combines both information (data), and operations (code). Graph below show the OOP. 



Structuring of OOP:

Classes
-       think of attributes and behaviour of your new class
-       identify noun (this is a candidate for class name)
-       identify verbs the noun uses (candidates for behaviour of the class)
-       identify less-important nouns (candidates for attributes of the class)

Methods
-       may compute and report some property related to a class instance
-       may change (AKA mutate) some properties of the instance (ex: the __init__ function)
-       they are attached to a class instance, and they use information from that instance to do their work

Special Methods
 __eq__
-       used to check whether some object is equivalent to another object

·      __str__
-       creates a str representation that is easy to understand
-       note: if you do not implement __str__, Python will use __repr__ in its place

·      __repr__
-       evaluate the str representation into an equivalent instance, so that you can examine it

week 3 why geeks should write?

Comparing computer programmers with writers, they are quiet similar with each other. What a writer is trying to do is expressing his ideas using appropriate language to captivate their readers. Similarly, goals for a  programmer is writing codes with clear manner and logic to solve or accomplish certain tasks.

 The idea of ' why geeks should write ', is to try to structure thoughts. Before writing codes, programmers should organize the steps to accomplish functions, and write propose of  each steps, then convert the words into codes. In other words, programmers should plan their codes before start to write it. 

All in all, writing skills are very important for all geeks, because not only does it help organize our thoughts, but also convey them in a way other people will fully understand.

2015年2月13日星期五

week 7 Impressions of tracing recursion

Until this week, I have learnt two different types of tracing recursion, the first one is taking a list of list as parameter and the second one is about python Tree.

Taking a list of list is not hard to trace, for example:

let x = [[2,3], 3 , 4, 5], then f(x) will return 5. To trace recursion, there are 4 items in x and the first item itself contains 2 item. The tracing of this recursion is shown below:

>>> sum(f([2,3], f(3), f(4), f(5))
>>> sum(f(2), f(3), 1, 1, 1)
>>> sum(1, 1, 1, 1, 1)
5

This kind of recursion is simple. f(x) will  need to check if x is a list, (in this case x is a list) then it will sum all f(a) where a is every element in x. Further more, this function will continue to check if item in x is a list, finally reach the inner-most list.

This kind of recursion seems easy for me, because I have experienced this kind of logic. However, to trace recursion for python Tree is difficult for me. The structure of Tree is new and I don't know how computer will process the data in what order and logic. There is an example in Lab.


For tracing the BTNode tree, I was so confused how computer will process data from tree structure. I read some others slogs and I got some idea about tracing recursion. 
http://fifislog148.blogspot.ca/

In the function insert, it will insert a data in BTNode in appropriate position. The function will first check if node is empty, if not, it will compare data with node.data, and if data is smaller, then data will be posited on left, otherwise right. Here we need a recursion to get the right position for data. In the recursion, function will take node.left as a central position and check its left and right, until no children is left.