Saturday, April 4, 2015

Week #12: My last impressions.

This is my final post for CSC 148. Is it already the last one? I can't believe it! One thing I realized is that I enjoyed learning recursion the most in this course. I found assignment 3 as the easiest assignment as I already practiced recursion a lot throughout the course. I really had troubles with recursion at first, but with the help from professors and SLOG posts, I feel very confident in recursion. I think minimax strategy for Assignment 2 was the hardest challenge for me throughout the term. I would like to learn more strategies for game in the future.

 As an advice, I really want this course and CSC 165 to continue having SLOG assignment as it allows one to review the course materials efficiently. With the help of SLOG posts, I was able to study for two term tests. Writing SLOG posts really helped and improved my understanding of the course materials. Not only that, looking at others' SLOG posts enabled me to view problems in different aspects and approaches. I posted my SLOG posts weekly to review what I learnt during that week.

Now, it's time for me to study for CSC 148 final exam which is worth 40%! I would like to thank my TAs and professors for their supports throughout the term. Taking CSC 148 course has improved my Python skills significantly! Thank you very much and I wish good luck to everyone who is going to take CSC 148 final exam.Thank you once again!

I found some interesting SLOG, so I commented on them. Their understandings of the course materials are outstanding. The links are shown below.
http://such148muchcsc.blogspot.ca/
http://csc148lizhechen.blogspot.ca/
http://csc148experience.blogspot.ca/

Thank you very much for this wonderful term, everyone! See you next time!

Saturday, March 28, 2015

Week #11: Revisiting my previous SLOG posts

I cannot believe that my CS first year is almost done at U of T. Studying CSC 148 developed me as a better software developer although the only language I know is Python. I am planning to study C by myself during summer vacation to prepare for my second year as CS undergraduate at U of T.

Looking at my posts, I am proud that at least I kept writing my SLOG posts weekly which shows my dedication and passion towards this course. I believe that writing SLOG post is very helpful as it allows me to review the course material. Not only that, reading others' SLOG posts enables me to view the course materials in different aspects. Writing about why computer scientists should write on my first post allowed me to reflect on the importance of writing even in subjects like computer science. Computer science is not all about code-writing. Computer science is essential in our daily lives. I am glad that I study computer science at U of T.

I also agree with my previous posts that using office hours wisely is one of the best learning methods. Instead of struggling over one question for 2-3 hours, asking a question to Professor Heap after some attempts saves my time and teaches me more than any other method. What I was confused about at first was recursion, so I visited Professor Heap to talk about it. With his help, I am now confident in my recursion skills. I also attempted another method. As shown on my week 7 post, when my partner and I had problems with lab 05, we attempted a new method where the first one writes code and the next one tries to debug it. That was also a success although it took us some time. I guess there are many ways of learning in computer science. I believe that these two methods suit me the most as these assisted me to learn CSC148 in depth.

Tracing recursion was the easiest as I was able to see the pattern clearly. I got perfect on that quiz. Interestingly, I've revisited my week 5 post when I was learning recursion more in depth during week 6-8 to re-enforce the basic concepts of recursion. Likewise, revisiting  my previous posts always helped me to review the course materials throughout the term.

Writing SLOG posts helped me reflect on the course materials and myself. Whenever I wrote my posts, I always tried my best to demonstrate my understanding so that I can revisit later during the final exam preparation period and other students might find my posts useful.

It was a challenge for me to actually find SLOG posts which was updated weekly. Most of the SLOG blog were inactive. I wonder why students gave up on writing SLOG posts weekly. Is it because they don't have time? I believe that writing SLOG post does not take too much time. Even writing just a bit is fine if one is so busy.

I am glad that TA strike is finally over. I would like to thank both TA and U of T as they have decided to settle the strike. The final exam period is also approaching. I hope that CSC 148 final exam is easy. It's time for me to study! You can do it, Julian!

I also found these SLOG blogs fascinating as the writers kept writing weekly just like me. Not only that, their explanation on the course materials was great. I also commented on how great works they have done. Here are the links below.
http://csc148sonny.blogspot.ca/
http://aquaticliving.blog.com/   <- I wasn't able to comment on it since the comment option was not
                                                  available, but I want to say "don't give up!" to the writer. I am sure                                                     that the writer can overcome the challenge he or she is facing currently.
http://csc148eunn.blogspot.ca/

Their postson CSC 148 course materials are very impressive. They have demonstrated their approaches to problems in depth and how they interpret problems differently. Not only that, their summaries are in detail and well-organized. I also agree with most of their posts and I want to say great work to those who constantly wrote his or her SLOG posts.

Friday, March 20, 2015

Week #10: My impressions of Week 9

We had only one lecture class for Week 9 since we had term 2 test on Wednesday. For the term test, I just hope that I achieved A on it. Professor Heap also clarified on which subjects are included for the test. Thanks to Professor Heap, I exactly knew what I had to study for. I would like to thank Professor Heap for his works.

During week 9, we focused on BST (Binary Search Tree) and its methods insert and delete. As the course material was fairly straight forward, I had no problem understanding the concept. Although I was confused by random module for Lab #8, my friend and I worked on it together. I also used Danny's office hours in order to understand the basic concept since I've realized that asking a question to professors is a much better than struggling over the question for 2 to 3 hours. One thing I noticed is that the course material for lab #8 will be revisited in different ways for CSC 263. This means that if I do not understand the problem and just ignore, this will once again come and cause problems to me later in CSC263 or other CS courses. Thankfully, with the help from Professor Heap, I understood the problem perfectly.

I would like to demonstrate some basic implementations for BST, insert and delete methods. For BST, we also need class BTNode. However, I will skip on the implementation part of BTNode as I've discussed before on my previous posts. The source is from lab 08 by Professor Danny Heap.

Now then, for class BST. 
(Source:  http://www.cdf.toronto.edu/~csc148h/winter/Labs/lab08/bst.py)

class BST:
"""Binary search tree.""" def __init__(self: 'BST', root: BTNode=None) -> None:
"""Create BST with BTNode root."""
self._root = root
def __repr__(self: 'BST') -> str:
"""Represent this binary search tree."""
return 'BST({})'.format(repr(self._root))
def find(self: 'BST', data: object) -> BTNode:
"""Return node containing data, otherwise return None."""
return _find(self._root, data)

(Source:  http://www.cdf.toronto.edu/~csc148h/winter/Labs/lab08/bst.py)




What I want to demonstrate now is insert and delete methods.
(Source:  http://www.cdf.toronto.edu/~csc148h/winter/Labs/lab08/bst.py)
def _insert(node: BTNode, data: object) -> BTNode: """Insert data in BST rooted at node, if necessary, and return root.""" 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
def _delete(node: BTNode, data: object) -> BTNode: """Delete, if exists, node with data and return resulting tree.""" return_node = node if not node: pass elif data < node.data: node.left = _delete(node.left, data) elif data > node.data: node.right = _delete(node.right, data) elif not node.left: return_node = node.right elif not node.right: return_node = node.left else: node.data = _find_max(node.left).data node.left = _delete(node.left, node.data) return return_node
(Source:  http://www.cdf.toronto.edu/~csc148h/winter/Labs/lab08/bst.py)

Professor Danny Heap kindly provided us with the implementation of BST methods insert and delete. Although I had trouble understanding these methods, I got used to it soon as I've already experienced various Binary Search Tree. I think my experience on previous lab exercises also helped me understand lab 8 materials. I believe that doing lab exercises help me study and understand the course materials and develop me as a better computer scientist. 

Saturday, March 14, 2015

Week #9: My impressions of week 8

During week 8, we learnt about linked list and LLNode. Learning linked list was difficult compared to other aspects of computer science.  What professor Danny emphasized on was to draw pictures for linked lists. At first, I was not used to drawing diagrams to represent linked lists. However, I practiced drawing diagrams to understand linked lists. Interestingly, the last question of the test actually asked for a diagram for linked lists.

LLNode was very easy to understand as it is a node for linked list. I would like to demonstrate implementations to initialize LLNode and LinkedList based on Danny's lectures. (Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Danny/W8/node.py)

class LLNode:
    def __init__(self, value, nxt=None):
        """ (LLNode, object, LLNode) -> NoneType
     
        Initialize LLNode with value and nxt
        """
        self.value, self.nxt = value, nxt

class LinkedList:
    def __init__(self):
    """ (LinkedList) -> NoneType
 
    Initialize LinkedList self by making an empty linked list.
    """
    self.front, self.back = None, None
    self.size = 0
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Danny/W8/node.py)

The most difficult part was to implement methods like __contains__ in order to find whether it contains a certain number or word. So I would like to go over __contains__ method on this post. The following implementation for __contains__ is from Danny's slides. I added comments to go over the implementation step by step. (Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Danny/W8/node.py)

def __contains__(self, value):
    """ (LinkedList, object) -> bool
 
    Return True iff LinkedList self contains value.
 
    """
    cur_node = self.front    #Here we set a new variable called cur_node
    while cur_node:       #check whether cur_node exists
        if cur_node.value == value:     # if the first element of LinkedList contains value
            return True           # return True
        cur_node = cur_node.nxt      # if not, we move onto the next element of LinkedList
    return False       # there is no cur_node as it reached the end of LinkedList
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Danny/W8/node.py)

Learning about LinkedList enabled me to understand computer science in depth. Although it's just a basic material for typical computer scientists, it is a huge achievement for a newcomer like me to learn and understand LinkedList concepts.

During this week, I spent three days studying for CSC 148 term 2 test. I first reviewed Danny and Diane's lecture slides and lab materials. Then, I tried solving five past exams. What I always had the challenge the most was LinkedList part. In order to overcome this challenge, I tried implementing new methods for class LinkedList. Not only that, I always tried to solve the past exam within 50 minutes. The term test was not that hard, but the last question was quite confusing to me. Sadly, the last question was about LinkedList. Although I am not 100% sure about my answer for the last question, I tried my best, so I have no regret. I hope to achieve A on this term test.

I also visited other students' SLOGs in order to learn how other students approach CSC148 and its course materials. Unfortunately, some of the SLOGs were inactive. The following links are the SLOG posts which I found interesting and left some comments.

http://148wuboyangw3.blogspot.ca/

http://computersciencemaggie.blogspot.ca/2015/03/summary-of-object-oriented-programming.html?showComment=1426384453547

http://csc148slog1001429162.blogspot.ca/2015/03/linked-lists.html#comment-form





Saturday, March 7, 2015

Week #8: My impressions of Week 7

During last week, I spent lots of time on implementing function and methods for Assignment 2. My partner and I faced many challenges. Instead of struggling over the problems we faced, we met Professor Heap during his office hours for any hint. What we had the problem the most was minimax. At first time, I thought that I could implement that quickly with no problem. But that was wrong. My partner and I tried implementing minimax strategy for three days, but it did not work.  So we visited Professor Heap three times in order to understand what minimax strategy actually does. With the help of Professor Heap, we were able to understand the minimax materials. One thing I realized was to use office hours wisely. Professor Heap was always willing to help us whenever we visited him. I would like to thank Professor Heap for his hard work.

During the lectures in Week 7, Professor Heap explained briefly about Assignment 2. It seemed that many people had the same  problem as me. The lectures mostly focused on a binary tree. BTNode should have two children. So we initialized it like below.  (Source:  http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Danny/W7/monday-annotated.pdf)

class BTNode:
    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
(Source:  http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Danny/W7/monday-annotated.pdf)

Initializing BTNode was easy as we learnt it during Lab 06 as well. However, writing an implementation to evaluate a binary expression tree was a challenge to me. In order to check all the leaves in the node, we had to use recursion.

I also learnt Tree traversal. There are 3 Tree traversal called in-order traversal, pre-order traversal and post-order traversal. I referred to Diane's week 7 lecture slides in order to understand what these three are. The definitions for these three terms are from Diane's slides.
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Diane/w7/Trees-2.pdf)
In-order traversal checks a node in between checking its two children
Pre-order traversal checks a node before its children
Post-order traversal checks a node after its children
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Diane/w7/Trees-2.pdf)

Week 7 was very easy compared to other weeks. I guess it's because week 7 is a combination of recursion and BTNode that I've already studied before. I believe that my CS skills are improving everyday as I practice implementing various functions and methods during my spare time. I hope TA strike will settle soon with good results for both the university and TAs.

Friday, February 27, 2015

Week 7 Recursion

I would like to talk about Recursion for week 7 CSC 148 SLOG post. Although I've briefly talked about it on Week 5 tracing recursion and unit tests post, there are new materials that I learnt after posting my Week 5 SLOG. Recursion is very important in Python 3 as it allows the clients to check from a root to leaves in class tree.

I would like to go over the terms for tree as knowing these terms is very crucial in order to understand recursion. The terms are leaf, depth, root, internal node and arity.

The definition of these terms are based on Danny's Week 6 lecture note.
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Danny/W6/w6.pdf)

Leaf - a node that does not have any children
Depth - Height of the entire tree - height of a node
Root - first one node
Internal node - a node with one or more children
Arity - maximum number of children for nodes
(Source: http://www.cdf.utoronto.ca/~csc148h/winter/Lectures/Danny/W6/w6.pdf)

I had problems understanding these terms when I first encountered. I thought that leaves which are located at the bottom of the tree in a tree diagram are roots. However, I soon realized that the first node should be a root which supports a whole tree.

First, I would like to  revisit my week 5 SLOG post. Week 5 was mostly based on tracing recursion rather than implementation of recursion. So I had no problem understanding the materials.

I posted the tracing count_elements  recursion problem that I had posted on Week 5 SLOG post below. (Lab 3 Source: http://www.cdf.toronto.edu/~csc148h/winter/Labs/lab03/handout.pdf).

def count_elements(L):
    """ (list or non-list) -> int

    Return 1 if L is a non-list, or number of non-list elements in possibly-nested list L.
    """

    if isinstance(L, list):
        return sum([count_elements(x) for x in L])
    else:
        return 1
                              (Source: http://www.cdf.toronto.edu/~csc148h/winter/Labs/lab03/handout.pdf).

1. count_elements('snork') -> 1  # since 'snork' is a non-list
2. count_elements([2, 1, 3]) -> sum([count_elements(x) for x in [2, 1, 3])
                                             -> sum([1, 1, 1])  # already traced count_elements(int)
                                              -> 1+ 1 + 1
                                             -> 3
3. count_elements([2, 1, 3, '[4]']) -> sum([count_elements(x) for x in [2, 1, 3, '[4]'])
                                                      -> sum([1, 1, 1, 1]) # already traced count_elements(int) and                                                                                                   # count_elements(str) before
                                                      -> 1 + 1 + 1 + 1
                                                      -> 4
4. count_elements([7, [2, 1, 3], 9, [3, 2, 4]]) -> sum([count_elements(x) for x in [7, [2, 1, 3], 9, [3, 2,  4]]) 
                                                           -> sum([1, 3, 1, 3])     # already traced count_elements(list of                                                                                                                                        # int) before
                                                            -> 8
                            (Source: http://www.cdf.toronto.edu/~csc148h/winter/Labs/lab03/handout.pdf).

What I had the troubles the most were Lab 5 and Lab 6. For lab 5, I first tried to work alone trying to implement list_all, list_leaves, list_interior, list_if and list_to_depth at home. However, after 30 tries, I realized that I am not fully understanding recursion material. So I reviewed lab 3 and Danny's slides on recursion for two hours. But as I was not able to implement even a single method. I was so tired. That was when I decided to work with my friend as a pair to crack this problem.

The way he and I did to solve the problems for lab 5 is shown below.
1. First, I wrote codes for each method of a Tree and tried to run it.
2. My friend took a look at the outcome and tried to debug it by adding or writing some new codes in it.
3. Each of us takes a turn to debug the code until the result shows no problem.

Although we spent quite a lot of time doing this process, we actually achieved to implement all the codes. One thing I learnt through this process is that working together is more efficient if it is allowed. He and I were so happy that we solved the problem.

We tried the same thing for lab 6. At first, we had no clue on how to implement the methods for class BTNode. However, we tackled the problem in various perspectives and searched about binary tree to learn about what binary tree is. After two hours of coding at Bahen Centre, we completed all the implementation of methods for class BTNode. He and I were so glad that we were able to finish it. Although a programmer suffers lots of stress while coding, the feeling he or she gets when the implementation is done is really amazing.

During the lab 6 section, I tried to implement additional exercises posted by Danny and Diane. I posted the implementation for leaf_count method for class BTNode below in order to demonstrate my understanding on recursion.
       if t is None:
           return 0
       else:
           return sum([count(t.left), count(t.right)])

(Source: http://www.cdf.toronto.edu/~csc148h/winter/Labs/lab06/additional.py)
def count(t):
    ''' (BTNode) -> int

    Return the number of nodes in BTNode t.

    >>> tree = BTNode(5)
    >>> count(tree)
    1
    >>> 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)
    >>> count(tree)
    7
    '''
    if t is None:
        return 0
    else:
        return sum([count(t.left), count(t.right)]) + 1
(Source: http://www.cdf.toronto.edu/~csc148h/winter/Labs/lab06/additional.py)
As I fully understood recursion materials, I had no problem with lab 5 and 6 quizzes. I am glad that I am taking Computer Science at U of T. I commented on other students' SLOG posts that are interesting. One thing I found was thatmost of them wrote on recursion. 
http://alexandraamatuzio.blogspot.ca/2015/02/recursion.html?showComment=1425098064316#c695105407004633210
http://lhzuigao.blogspot.ca/2015/02/summary-of-object-oriented-programming.html?showComment=1425098326916#c5293325936651694830




Thursday, February 12, 2015

Week #6: Object-Oriented Programming Concepts

When I first thought of Object-Oriented Programming, I had no clue what this term means. However, as I started to study Computer Science, my knowledge in Object-Oriented Programming is improved. Object-Oriented Programming is a programming where we mainly focus on objects themselves instead of its way to get to the solution. Some examples of Object-Oriented Programming are C++, Java and Python.

Some basic components of Object-Oriented Programming are class, object, method, instance and recursion.

We already learnt what class is and how to create a class. I will implement only the init method for each class. I will also try to explain instances in Python.
For example,
class Cake:
    def __init__(self, candle, topping):
        """ (Cake, int, str) -> NoneType
       
        Initialize class Cake with candle and topping
        """
        self.candle = candle    # This can be considered as instance variable for specific instance
        self.topping = topping

We can use inheritance to use class Cake in other class like a class CheeseCake to pass the information that class Cake contains to a new class CheeseCake. I will also demonstrate class variable in class CheeseCake. Object-oriented Programming can have multiple inheritance.

class CheeseCake(Cake):
    Cake_List = []     #This is the variable class that is shared inside the class
    def __init__(self, candle, topping):
        """ (CheeseCake, int, str) -> NoneType

        Initialize class CheeseCake with candle and topping
        """
        Cake.__init__(self, candle, topping)

Method is based on object. For Python, we learnt that method is inside a class of an object.

class Feeling:
    def tired(self, feeling):
        #body implementation omitted

def tired(self, feeling) is considered a method since it is inside a class Feeling.

However, function is different compared to method. Function does not depend on object.
def hello(self, greeting):
    #body implementation omitted

def hello(self, greeting) is considered a function as it is not inside class of an object.

We can think of a method as a function that depends on an object like class.

Interestingly, recursion is also one of the basic concepts in Object-Oriented Programming.
As I've already covered this topic deeply in previous SLOG posts, I will skip this one.

Object-Oriented Programming has now become a significant part of our CS society. Although the only OOP I know is Python, I hope to learn Java and C++ during my third and fourth years at UofT. Another thing I found interesting is the number of OOP. There are more than 20 OOPs in the world. I guess I cannot master all of them. Instead, I will study 2 or 3 OOPs in depth for my future career.

Learning OOP is so interesting to me. Maybe, in the future, I hope to create a new OOP that is much easier than Python so that anyone can learn OOP.