Saturday, 4 April 2015

Another slog for week 11

    Oops, I just saw the slog requirement for this week, so I decided to write another one.
    Here, I am revising the slog of week 8, where I said there can be another way of writing recursion rather than just  (...(c) for all the c in ...).
The other way, as stated in week 8 slog, is like this:
if root is None:
        pass
    else:
        inorder_visit(root.left, perform)
        perform(root)
        inorder_visit(root.right, perform)
In this way, every time we call on this method, if the node, which is the root of the subtree, is not None, the method will be again call on the left and right of that node in order. Well, it has been a long while since I read that slog. I found that the original way of writing recursion has left me with such deep an impression that it is the only way I can think of when dealing with recursion. I need to practice more on the second way. Also the use of eval and perform is also worth looking back on. I am glad I am reminded to revise my slogs, it is a great way to reinforce my knowledge and prepare for my test. 
   
So long, farewell!
  Dark Fox

Slog for week 12

    School is over, but this will not  be my last slog. Over the semester, I changed from someone who was even afraid of hearing the name 'computer science' to a big fan of it. It was of great help writing slogs to keep track of my questions and my progress. It encouraged me to learn more so that I can write more.
    This course is of good pace, and not very hard to follow in general. However, when TAs were on strike, it was a  real challenge for me to work things through without their help. I was kind of slow at getting the ideas taught in class, but the labs were really designed for people like me, to practice and examine my ideas.
    Over the semester, I have learned about class and subclass, stack and queue, nested list and tree(binary tree and best sorted tree), efficiency and most importantly, recursion. The reason why I think recursion is the most important is that it is the base of many other concepts listed above, and to be honest, it is really hard for me. Even though I have managed to use it right for a lot of times, I still need much practice: everytime when I am using it, it will still take me a lot of time to think carefully about it.
    Through this course I also met some good friends, like my assignment partners, who are really lovely. I love the way we worked together:  the brainstorm we had, the debugging process and the way we helped each other out.
    This course has got me interested in computer science every since I saw the professor using the turtle to draw something. I started to have creative ideas and use programming knowledge to design things for other subjects, such as a class of matrices in math and a program to simulate wave interference in physics. The more I learn, the more excited I am seeking for more.
    So I make a commitment here, though this is the last computer science course for my subject requirement, I will still keep learning computer science, either through other courses or on my own. My Slog journey has just begun.


Love
Dark Fox

Monday, 30 March 2015

slog for week 11

  WOW! BIG NEWS! The strike is finally over! I can't wait for the tutorial next week to see my lovely TA.
   This week we learnt about efficiency of sorts. We talked about bubble sort, selection sort, insertion sort and quick sort. Just a reminder, since it always happen to me that I mess these terms up, here are the illustration of these sorts.
 

 Looking directly at the illustrations may be the best way of understanding and memorizing these.
Efficiency is simply how the time to sort a list of n elements varies with n.
In the pictures for selection sort and insertion sort, it is already given the efficiencies and the way to get those.
For bubble sort, which in my opinion is the simplest one, it needs to go through every element after the starting one, so
it is just (n - 1) + (n - 2) +... + 2 + 1 which is 0.5 * n * ( n - 1), the efficiency is n ^ 2.
And for quick sort, it is a little complicated, where we have to think of whether the sort is well-balanced or not. In the well-balanced case, we divide the list log(n) times, and in the worst case, n times.
In both cases, we need to go over the whole list (except the pivot points), which is proportional to n. Thus, the efficiency is nlog(n) in the best case and n^2 in the worst.

Above is my summary of this week. Thank you and goodbye.

P.s. CAN'T WAIT FOR THE TUTORIAL!!!

Dark Fox

Friday, 20 March 2015

slog for week 10

  This week we learnt about assertion. In the slides it is written in the form as below:
      assert <condition> , <error_string>
---> if not condition: raise AssertionError(error_string)
I understand this form but I do not really see the point of this. Is it just a simpler form of if statement? Why and where do we use it? It is disappointing that I did not find any real examples in the course material. And there was no TA in the tutorial either. When I asked my friends, the answer was not clear and I can tell that this is not just my problem.
   Besides the course, I also used computer science elsewhere, which is really cool to me. In physics, we had practicals using python and vpython, to make the diagram and animation of waves. And for linear algebra, my friend and I tried to create classes of matrix, vector and vector spaces. And we even tried to write codes so that it will solve the polynomials we input. I have been focusing on learning how to use Sqlite these days. I think I am slowly falling in love with computer science. This is a great change of mind, since I used to hate it somehow. Now, the feeling that I can actually command the computer to do what I want in a much easier way than doing by hands is of great satisfaction. I hope I can learn more about coding, and use it more. 

   May the passion be always with me. And I will try to figure out the assertion of course.

  Thanks for listening to me.
  
  Tschuss!

  Dark Fox

Thursday, 5 March 2015

slog for week 9

   This week we learnt about linked lists, which we can think of in two ways.

1. as lists made up of an item (value) and a sub-list (rest)
2. as objects (nodes) with a value and a reference to other similar objects
   Then we started to implement the methods. At first, this process is kind of difficult since it is easy to lose track of what I was doing and what I should do next. I have to set an example for myself, and keeping turning to it. Then the professor told us to draw pictures while writing the code. That really helped. When using this method, I would not lose track as much and would not forget anything that I should do.
   It is so sad that we did not have practical this week. Computer science practicals are always the ones I love the best; the TA is really helpful and patient. I learnt a lot from the practicals past few weeks. Practice makes perfect, even if it will not make perfect, at least it can help you on the way to perfection. To get some practice, I went to the lab as usual, even though the TA was not there. I worked out several problems with the help of my friends, and had a better understanding of the topic. From merely imitating the code given by the professor to thinking independently, I learnt a lot.
For example, linked list can not be copied, I figured that out when I was trying to copy a linked list and it raised an error.
   Still have some  problems left undone. Thanks to my friends who have helped me a lot on the practical problems. I am going to work harder on it, and I will have my second term test next week.

Good luck to me and to everybody

Ciao
DarkFox

Wednesday, 25 February 2015

slog for week 8

This week we are learning about binary trees, in which each node only has at most two children.
 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

The use of the last line is smart!

Once we knew what a binary tree is, we learnt some methods used in this structure, for example, to evaluate it. The use of eval is said to be important, as in this line:
return eval(str(evaluate(b.left)) + b.data + str(evaluate(b.right)))

eval(...)
    eval(source[, globals[, locals]]) -> value
    
    Evaluate the source in the context of globals and locals.
    The source may be a string representing a Python expression
    or a code object as returned by compile().
    The globals must be a dictionary and locals can be any mapping,
    defaulting to the current globals and locals.
    If only globals is given, locals defaults to it.

However, I still have problem understanding how to use the 'eval' function. What does global and local refer to? I think I'm going to ask the TA in tomorrow's practical.

Furthermore, I learned the three orders, which are inorder, preorder and postorder.
Inorder is from left to right, as it was given in the class:
if root is None:
        pass
    else:
        inorder_visit(root.left, perform)
        perform(root)
        inorder_visit(root.right, perform)

Preorder is to evaluate from the root to the leaves, which goes like this:
        perform(root) 
        preorder_visit(root.left, perform)
        preorder_visit(root.right, perform)
And postorder is skipping the root and evaluate the leaves first, which I find a little bit hard to keep track of while tracing the order using a picture. However, it gets a lot easier just using the codes. That's to say, well, computer is smarter than me...
        preorder_visit(root.left, perform)
        preorder_visit(root.right, perform)
        perform(root) 

I also find it interesting that a recursion can be written in the way above and not necessarily using the form of return (...(c) for all the c in ...)

Above are the things I've learned this week, and more left to do for tomorrow's practical.
Fighting Dark Fox! 
Ciao!

Dark Fox

Saturday, 21 February 2015

slog for week 7

    This is reading week!
    Looking back on week 6, I have learned some interesting but also difficult things about tree.
 I have learned a lot of terminology. As a reminder, a tree has root, nodes, edges, leaves and subtree.

A path is a sequence of nodes n1, n2,..., nk, where there is an edge from ni to ni+1. The length of a path is the number of edges in it. The path is unique and it has no cycles.

The height is 1 + the maximum path length in a tree. A node also has a height, which is 1 + the maximum path length of the tree rooted at that node.

The depth is the height of the entire tree minus the height of a node is the depth of the node.

The arity or branching factor is the maximum number of children for any node.

After learning the terminology, I was taught to design codes to count leaves, count nodes, calculate the height and so on. An important method we used was recursion. First detect the base case, and then write the code for general case involving recursion. I could understand the code if it was already written, but it was hard for me to write recursion myself. In the practical this week, my partner and I only worked a few out with the help of our TA and piazza, which was so sad. Understanding what we should do was not the hard part, it was how we should do it that mattered. I think I still need some time to think about this carefully and try to catch up. If I could get the access to the answer to the practical after the every practical is done, that would be of great help to my study. After all, we first learn to imitate and then to think independently. I still need some more examples to grasp the clue of doing this.

Also I learned a format:
self.children = children.copy() if children else []
This is a functional 'if'. it means copy children if not none. The reason why we need to copy children 
is that we don't want to make change on the original data so that our counting method will not affect 
anything. 

I will work on recursion more and get a thorough understanding. I believe I can make it!~

Ciao my friend,
Dark Fox