2013年10月27日星期日

csc148_slog_linked_structure

    In the week 7, we learned linked structure in the lecture and practiced it in the lab and exercise.
    The first linked structure we learned is linked list. It is one of the cases of the linked structure, which has reference to only one object.
    Why do we sometimes use linked list rather than the normal list? I find the answer in the lab, in which we implement linked queue. In the timecheck of the linked queue, I find the time is a constant no matter how many numbers are in the linked queue, i.e. the time complexity is O(1), while the time complexity of the queue based on normal list, is O(n). From this case, we can see that linked structure shows the superiority in the operations such as insert.
    I would say something more about the difference between the implementation of linked queue and linked stack. In the linked queue, we have to keep track of both the top and the bottom but in linked stack we only keep track of the top object. The cause of this difference is that we dequeue on the top(by top, I mean the start node) but enqueue on the bottom(by bottom, I mean the end node). I don't think we can dequeue on the bottom and enqueue on the top, because it's always easier to find the children of a node rather than the parents of that node.



    Then we did something with the binary tree with linked nodes. The concept is the same to the binary tree based on python list, except that we need to use reference to the node rather than use the subscript of a python list.

2013年10月19日星期六

csc148_slog_recursion

    In week 4 and week 5 of CSC148, we learned something about recursion and recursive data type. It is a challenging topic for me at the beginning that I need a lot of time to figure out how recursive functions work.
    Recursion is really useful to computer scientists because sometimes we can solve the problems easily by using the function itself.
    Tower of Hanoi is a typical example. How to solve the Tower of Hanoi with 5 cheeses? It's just move the first 4 cheeses to the intermediate stool, then the fifth one to the destination stool, then the first 4 cheeses to the destination stool. We don't care how to move 4 cheeses because as long as we indicate how to move 1 cheese to the destination stool, the program will run recursively to the bottom case: move 1 cheese.
    I think the key to writing recursive function is:
        1.Find what we should do for the bottom case.
        2.Find the relationship between 'n case' and 'n-1 case' (return what? pass what argument to the 'n-1 case'?)
   The difficulty of witing recursive function is to work out a recursive algorithm, but once we work it out, the implemention will be much more easier.

csc148_slog_oop

    In the first three weeks of the CSC148, we learned the basic ideas of the object-oriented-programming. Object-oriented programming is a programming paradigm which focuses on classes and objects rather than constructing programs in a bunch of functions and data. Class will have attributes(data) and methods(functions) inside it and object is the instance of class.
    Object-oriented programming is the mainstream of programming currently. I think one of the reason is that the prototype of OOP is from the real world. In real world, all the things can fall into many categories, and it's just the idea of class. In real world, all the things have both attributes and functionality(e.g. dogs have 4 feet, dogs can bark), that is the idea of attributes and methods.
    Another important concept of OOP is inheritence. It comes from the real world too.Typically, in the taxonomy of animals, we human not only has the attributes of primate, but also has the attributes of mammal. By saying primate is a subclass of mammal, we will certainly know that human has the attributes of mammal without indicating them. In OOP, inheritence will make the code more concise and reduce the duplicate.
    Above all, OOP can enhance the readability of the programs and makes it easier to construct programs. That's why it is useful for computer scientists.