Saturday, 4 April 2015

Final Impressions

Looking back over the course, I learned some really interesting topics. Not too many programming techniques were taught, but a lot of important concepts were introduced. Classes, the building blocks of Python programming were a relatively simple topic covered and I managed to grasp that fairly well. Recursion was a challenging concept to work with for me personally. It is an important concept to master when it comes to creating efficient code. Different ADTs like stacks, trees and linked lists and how to manipulate them were also challenging. Although many concepts were challenging to me, it was a very good learning experience and I thoroughly enjoyed the 'eureka!' moment when I managed to create code that worked.

    A great hurdle that was consistent throughout the course was using recursion on the various ADTs. I struggled to finish lab work within the lab time limit and I didn't do exceptionally well on the quizzes. However, this slog was an exceptional help in helping me how to think properly when it came to creating proper code. I still have issues with linked lists so I'll have to keep practicing with that topic before the final exam. The TA strike was also a hurdle, not having access to TAs and labs were a bit detrimental since I couldn't ask for clarification during times when I had free time.

    Overall, I found that this course was a great help to my understanding and interest in computer science. I really do hope I manage to get enough marks to get into the program!





To my TA grader:

I have left comments on http://antiaromatic.blogspot.ca/2015/03/still-about-tippy.html, http://148slogger.blogspot.ca/2015/03/revisiting-my-early-impressions-of.html, and http://andrewlawslog.blogspot.ca/2015/03/week-11-recursion-revisited.html

Tuesday, 31 March 2015

Week 11: Revisiting a Previous Post

This week I shall be revisiting my week 4 post about recursion and recursion tracing. I still find recursion a very interesting topic and think it's a very important concept to master as recursion is a keystone of efficiency and efficiency is a primary concern among programmers. Although I think I have grasped how to do recursive functions, when it comes to implementation, I have difficulty implementing more advanced recursive functions. For example, the recursive functions that take multiple parameters and return multiple values such as the minimax functions.

    I think I have grown since my prior post when it comes to recursive functions. I can imagine how the function will play out in my head and it makes coding easier. I recall having difficulty finishing lab functions and it would make me feel a bit bad about not grasping it in time. However, after reading a couple of slogs regarding recursion, it makes me feel better knowing that I'm not alone in sometimes struggling to grasp things. This post echoes my sentiment, and this post that the previous poster linked does as well. Recursion with trees is another difficult concept to understand that we all seem to share. I do hope that we are all able to fully understand the material as we move forward.

Week 10: Testing Code

Ah, testing. I know it's terrible of me but I'm lazy with testing. I know it's a crucial part of creating beautiful and functional code but I'm always tired after creating functional code, especially during a time crunch. Proper testing will see if your code is able to break in the near infinite variations of applications that it's put through so it's very clear why it's important. You definitely want it to work in as many different situations as possible. Testing is doubly important when it comes to actual work submissions!

    Unittests in Python are the best way to implement test scenarios. It's built into Python and easily accessible with a bit of code. Unittests were a part of 108 but not a heavy part of 148, which is why I haven't gotten too used to them yet. We learned some new ways to implement unittests this week: the setup and teardown methods. Setup is used to prepare the test case, create any starting variables necessary for the function to work (e.g. setting up gamestates). Teardown is used to destroy the test case after setting it up to start a fresh case.

    I shall try my best to get into the habit of testing my code!

Week 9: More Binary Search Trees

This week we worked on more binary search trees focusing on manipulation of the data within the binary search tree. We had very limited exposure to the material that week due to the test but it certainly is something new. To insert or delete nodes from a binary search tree, which has a rather rigid format, and keeping the structure intact. Whereas the insert method is fairly simple to grasp in terms of coding, the delete method I find is much more difficult.

def delete(node, data):
    ''' (BTNode, data) -> BTNode

    Delete, if it exists, node with data and return resulting tree.

    >>> 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)
    >>> b = delete(b, 12)
    >>> print(b)
            14
        10
    8
            6
        4
            2
    <BLANKLINE>
    '''
    # Algorithm for delete:
    # 1. If this node is None, return that
    # 2. If data is less than node.data, delete it from left child and
    #     return this node
    # 3. If data is more than node.data, delete it from right child
    #     and return this node
    # 4. If node with data has fewer than two children,
    #     and you know one is None, return the other one
    # 5. If node with data has two non-None children,
    #     replace data with that of its largest child in the left subtree,
    #     and delete that child, and return this node
    return_node = node
    if node is None:
        pass
    elif node.data > data:
        node.left = delete(node.left, data)
    elif node.data < data:
        node.right = delete(node.right, data)
    elif node.left is None:
        return_node = node.right
    elif node.right is None:
        return_node = node.left
    else:
        node.data = _find_max(node.left).data
        node.left = delete(node.left, node.data)
    return return_node


    Here is the solution for this week's exercises. Conceptually, it is easy to grasp. If data satisfies the conditions for left and right nodes, delete those nodes. The difficult part comes when you have to rearrange the binary search tree to maintain the structure. You must check children and make sure that they are in the right spots while maintaining the recursive structure. I find that the more elements you add to a recursive code, the more likely it is to fail or run into errors. I certainly will need to practice more on binary search trees before the final!

Week 8: Linked Lists

Linked lists are another data type that is interesting to me. I think of linked lists as a freight train (especially as node data is called cargo!). As you manipulate the linked list, you are still able to keep the order of the list without disrupting other data. If you imagine a freight train, you can add another cargo car to an appropriate section of the train and link them together. The freight train maintains its structure while having additional data. All the nodes ahead of the new data are moved up one space and the head (the locomotive) is moved to the new front position. The nodes behind the new data are moved back one space and the end is moved back similarly. The scenario is similar for the opposite situation if you were to remove a node.

    A slog entry that I found helpful was http://148blog1.blogspot.ca/2015/03/linked-lists.html. This slog had succinct bite sized bits of info as to what linked lists are capable of, why they're useful and how to write them. A crucial point to take from it is to create a diagram (which is already very emphasized in the entry). It really helps to stimulate how you think about how a linked list functions and how it reacts when manipulated.

Week 7: Recursion

As I have mentioned in a previous post, I find recursion fascinating, although confusing at the same time. Recursion tracing over functions and methods seems simple, however, creating recursive functions that do exactly what you want is proving a little difficult for me personally. Going through some of the lab functions on recursion, it seems simple, but when you're trying to find something a bit more specific or more advanced it becomes troublesome.

    Simple functions like the ones from a prior lab and from lectures are great for general understanding although I would love for some more advanced examples to get a hang of things. The count and contains methods for BTNodes explained in lecture were easy to grasp.

def contains(node, value):
    ''' (BTNode, object) -> value

    Return whether tree rooted at node contains value.

    >>> contains(None, 5)
    False
    >>> contains(BTNode(5, BTNode(7), BTNode(9)), 7)
    True
    '''
    if node is None:
        return False
    else:
        return (node.data == value or 
                contains(node.left, value) or 
                contains(node.right, value))


    In this method, it's very easy to follow along. If the node is empty/doesn't exist, return False as there is no node that contains value. Otherwise, return whether the current node's data contains value or recursively check every left and right node for the value until the end. I do find help from other sloggers though. One slog that has been a big help has been http://antiaromatic.blogspot.ca/. This blog posted their solutions to labs which really helped me a lot when it came to thinking about how to design functions.

    When it comes to more advanced functions that search for specific things and return it in a specific way, it gets a little hectic. For example, for assignment 2, we are suggested to create a helper function that recursively searches through game states and return a minimized value for the opponent while returning a maximized value for self (thus the term minimax). This type of function seems like a far stretch in comparison. To create a list of gamestates, search them, determine the weakest move, return an integer value as well as a move recursively was quite difficult!

    However, this is not to say that the challenge wasn't a good thing! Challenging content is the way to create the best thinkers in my opinion.

Tuesday, 17 February 2015

Object Oriented Programming

Object oriented programming is quite fascinating. It certainly is much more challenging than the introductory concepts introduced in CSC108. Instead of relying on the built in classes and functions, we're now creating our own, from the ground up. Instead of keeping track of one object going through simple functions to attain relatively simple goals, we're keeping track of objects going through multiple classes that we designed, possibly multiple instances, class methods, special methods and more. Now, we can create more interactive code that achieves more advanced goals.

    Learning about classes, I initially found them to be a bit annoying and confusing. I thought to myself, "Why can't we just do what we did in 108? What is this self nonsense? Instances? Bleh." But, over time, I realized how important creating our own classes were. They are the building blocks for what we wish to create beyond the limitations of the built in classes of Python. It took me a bit but I eventually got the hang of creating classes.

    The concept of recursion is interesting as I've stated in my previous entry. I still haven't fully gotten the hang of it but it is a bit of a relief to see that other students are struggling a bit with it like I am. Like in this slog, http://samcao918.blogspot.ca/2015/02/week-5-slog.html, this student similarly had trouble with recursion but eventually got over that hurdle and figured out how useful recursion could be. Hopefully, I will understand it better with additional practice over reading week. Any tips for figuring out recursion? I know that we have to figure out the base case and then find a way to keep the function going until it reaches the desired effect, but I'm having difficulty in figuring out exactly how to design past the base case. I've always had trouble figuring out problems like this.