Tuesday, 31 March 2015

week 12

It is finally approach to end of the year. It is a really good chance to take a step back and look what I learned this term from up to down.

Looking back to my previous slogs, I agree mostly what I wrote before. I learned new things of coding that higher level of csc 108 such that short if statement into a single line or implementation of subclass in class. Those things are kind of refreshing my memory as I learned them in previous course. However, recursion, ADT and linked list are new and quite challenging to me. I was confused about their concepts and implementation at first time, though the assignments and exercises have helped me understand how to go about creating functions relevant to them. In my opinion, the hardest and most important part in csc 148 is implementing recursion in your function. From A1 that simply using basic recursion to A3 that almost every function needs to contain recursion otherwise will be awkward. Last but not the least, we have seen the running time and algorithms which is the similar topic we have covered in csc 165.


Overall, I decided continuing studying computer science in later years, as it is helpful and useful in the future.

week 11

Looking back my earlier slog, I would like to discuss my slog in week 7 which is about first impression of recursion.

"However, I found it quite confusing when I first time be introduced the concept of it. It is easy to start with single list and couple sublists." This is what i said in week 7 of my impression about recursion. Meanwhile, that was first time I learned this method. However, I realized that recursion is not as easy as I thought  like define how many times recursion is are in function or just keep calling function itself over and over again. Those are the basic concept and only the tip of iceberg. During a month studying, I gradually found out recursion has more knowledge  need me to learn than what I thought such that minimax and linked list. Through out the term, concept of recursion has been used in almost every function. What we mostly test on is recursion. 

I have better understanding of recursion right now but not fully understand such that minimax. I hope I will figure this out before the final exam.


 I read many different peers' slogs. Some of them are outstanding and including deeply thought. 


For example, http://dottoripy.blogspot.ca.

He writes slogs detailed every week, which covers all the knowledge we learned in that week and comes up thought or question about new things. He always gives some example function calls and fully explained them. I have to improve my writing skills in order to express my thought in better way.


Below are some URL that I commented to other peers:

http://audreyfang.blogspot.ca/2015/03/csc148-lecture-week-8.html?showComment=1428014678702


http://computerscienceuoft.blogspot.ca/2015/03/week-11-revisit-previous-slog.html?showComment=1428015314549

Monday, 23 March 2015

week 10

Because of term test two, we only had one hour class. Our class firstly took a little bit of time to look back assignment 2. I am still have trouble with implementation of minimax. I hope it will get clear after office hour next week. Then we covered new material ---assertion. Assert calls make our coding life easier as it could check the bugs that we have in our program. Not only checking bugs, but also tell me exactly which case was failed. It saves time and makes more convenient  for us to debug.

More over, we have discuessed in BST again but more deeply such that insert and delete function(lab) which was similar to what we covered couple weeks ago.

def insert(node, data):
    ''' (BTNode, object) -> BTNode

    Insert data in BST rooted at node if necessary, and return new root.

    >>> b = BTNode(8)
    >>> b = insert(b, 4)
    >>> b = insert(b, 2)
    >>> b = insert(b, 6)
    >>> b = insert(b, 12)
    >>> b = insert(b, 14)
    >>> b = insert(b, 10)
    >>> print(b)
            14
        12
            10
    8
            6
        4
            2
    <BLANKLINE>
    '''
    return_node = node
    if not node:
        return_node = BTNode(data)
    elif data < node.data:
        node.left = insert(node.left, data)
    elif data > node.data:
        node.right = insert(node.right, data)
    else:  # nothing to do
        pass
    return return_node

The complete  insert function as show above. The insert function basically just search the correct position and insert value into corresponding place. Function runs recursively that go through elements in tree and put value in right position.

Sunday, 15 March 2015

week 9

During the lecture from last week, prof introduced new term to us ---'Linked List'. It was an useful function for us to use during programming. The most advantage of linked list is that we can use it to insert any value to anywhere in the stacks without changing order of the whole stacks information.


As the picture shows above. We can generally divide linked node by three types: start node, intermediate nodes and end node. Start node refers to 'head' in the picture. For this node, it only connect with other behind it but front it. Intermediate nodes connect to previous node and next node. There exists space for memorizing the address of next node. The 'tail' refers to the end node which only connect to previous node. Because there is 'room' for node to store address of connecting node, we can easily manipulate its address to change its order or modify them. One thing we should keep in mind while using linked list is that linked list cannot be indexed but iterate over and go through the list.


Monday, 9 March 2015

week 8

The new concept of Binary Search Trees is being introduced in lecture this week. BST is the special tree category as structure is different than normal tree. Each BST node at most has two children. Each value that is smaller than the root is contained in the left sub-tree while each value larger than the root is contained in the right sub-tree. We can use binary search method in BST. One of the advantage of BST is that binary search cuts its search steps in half every time it does not find its desired value, the binary search is more efficient and quicker. 


def find(node, data):
    ''' (BTNode, object) -> BTNode

    Return the BTNode containing data, or else None.

    >>> b = BTNode(5, BTNode(4))
    >>> find(b, 7) is None
    True
    >>> find(b, 4)
    BTNode(4, None, None)
    '''
    if not node or node.data == data:
        return node
    else:
        return (find(node.left, data) if (data < node.data)
                else find(node.right, data))
As code shows above, BST will search the specific value. If the value less than node, then it cuts right tree and only search left tree. Reversely, it establishes as well. 

In addition, there are three approach of BST: preorder, postorder and inorder. These three orders has been tested on term test 2.

Sunday, 1 March 2015

week 7 summery of recursive

I found tracing recursion is kind of fun and relatively easier than previous knowledge. However, I found it quite confusing when I first time be introduced the concept of it. It is easy to start with single list and couple sublists. I have to understand the simplest list and two elements list, then I can continually figure out the rest of recursion. But this is just a general way to solving recursive cases. As numbers of sublists are increasing, it is difficult to trace it correctly. When I brought my question to lab, TA explained tracing recursion step by step and I got better clue of it. The function keeps calling it self until it reach to the end. Recursion is efficient and useful during our programming. I realize the only way to have better understanding is writing and solving more recursive cases. 

During A2, I have used recursion in every function. It could simplify function call for itself. For example, in binary search tree, we can apply recursive during our search so that searching recursively go through from left to right in order to find the specific value in shorter time.



def list_internal_between(node, start, end):
        ''' (BTNode, object, object) ->

        Return a Python list of the data from all internal nodes of
        the tree rooted at node that are between start and end,
        inclusive.

        >>> list_internal_between(None, 3, 13)
        []
        >>> b = BTNode(8)
        >>> b = insert(b, 4)
        >>> b = insert(b, 2)
        >>> b = insert(b, 6)
        >>> b = insert(b, 12)
        >>> b = insert(b, 14)
        >>> b = insert(b, 10)
        >>> L = list_internal_between(b, 3, 13)
        >>> L.sort()
        >>> L
        [4, 8, 12]
        '''
        if node is None:
            return []
        else:
            left_list = (list_internal_between(node.left, start, end) 
                         if node.data > start
                         else [])
            right_list = (list_internal_between(node.right, start, end) 
                          if node.data < end 
                          else [])
            node_list = ([node.data]
                         if (start <= node.data <= end and not is_leaf(node)) 
                         else [])
            return left_list + node_list + right_list

For this function call, recursive function check children of the tree from left side to right side in post order. When we do the recursion, firstly, we break down the question into small pieces, then put them together or use them later.
            

Thursday, 12 February 2015

Week 5


I found tracing recursion is kind of fun and relatively easier than previous knowledge. However, I found it quite confusing when I first time be introduced the concept of it. It is easy to start with single list and couple sublists. As numbers of sublists are increasing, it is difficult to trace it correctly. When I brought my question to lab, TA explained tracing recursion step by step and I got better clue of it. The function keeps calling it self until it reach to the end. Recursion is efficient and useful during our programming.

Monday, 2 February 2015

Some thoughts of first month


   During first few 148 lectures, I realized this is real computer programming and no kidding. This course is level up of csc 108 and much harder than it. In csc 108, professor offered video lectures to us making sure that we have better understanding of course material. After studying csc 148 few weeks, I realized self-studying is the only way to keep on track. I felt two hours lectures not enough to absorb materials and intensive lab requires us to apply theory to practice which is a good way to learn programming. However, I still find this course is tough. The recursion part is quiet easy but class still confusing. In addition, I struggled in first assignment for a while as having difficulty understanding instruction. After discussing with prof and my partners, I got clues how it goes. All in all, often attending office hour and working with partners are necessary getting good grades in csc 148.

Friday, 23 January 2015

Why geeks should write?


Everyone has a gift in a unique and important way, even geeks. Geeks always been seen as nerdy, weird, the person that does not fit in our community. However, geeks’ thoughts are hard to understand and communicate with, I believe they should write as everyone has a gift. First of all, geeks rarely communicate with others as they steep themselves into a ‘geek world’. As a result, they have much more focus on research than others. People concentrating on one thing have high chance to be successful. Secondly, geeks usually have a unique thought than others. For instance, the finder of Facebook—Mark Zuckerberg has dropped Harvard when he started planning Facebook. Many people thought he was crazy at that time because he given up the top university in stead groping uncertain future. Although people cannot understand Mark and try to convince him that stay in Harvard, he did not listen to others and worked on Facebook. Finally, he made it. Proving to everyone quitting Harvard is not regret move. Therefore, geeks should write as they focus on one thing and do not influence by judgments. New thoughts with perseverance are equal to success.