Wednesday, March 30, 2016

Week 11 SLOG

Hello everyone, for the final time.
    It has been a pleasure writing these SLOGs and it was an interesting experience. Going back and reading through my SLOG was actually the best part of having a blog! What is quite apparent is how I seemed to begin to "get it" as the course went on. I still remember the first lecture I attended for CSC148... It hit me like a truck(I am putting this nicely). I had no idea what was going on, I felt extremely unprepared and I felt like everyone in the class had a massive advantage over me. The first lab was surprising, it really showed how LITTLE I knew of classes. I could not even finish half of the lab in the time we were given, and I received a 1/2 on the first quiz. I was frustrated. I finished the entire first lab on my own time after the lab session and I went to upper year students for help. They assisted me in understanding what a class really was, and what __init__, __str__, and __eq__ actually were. Things started looking much better for me after this. I decided to start writing the programs for lab in advance so that I could use my lab time for asking questions, or if I had no questions...... I would read reddit :). I started becoming more and more interested in programming as the course went on. To my surprise, I feel as if I have learned more valuable information in CSC148 than in any other course I have ever taken in my life, aside from maybe Multi Variable Calculus and Partial Differential Equations. I believe that an essential piece of the make-a-course-interesting-puzzle is to have charismatic instructors and TA's who can really get on the students level and help them out, and I was lucky enough to have a great TA. My TA, Brian, was always loud, fun and really grabbed your attention. He would never just give me the answers, but would tell me the general direction I should be looking in, which helped me learn how to see the problems in my code. I feel that this is what ALL TA's should do, not just in computer science, but in all disciplines.
    The earlier entry I would like to revisit is actually the entry where I wrote about my favorite topic of this course: Recursion. Aside from learning about the basics of what a class is and how they are useful, I feel as if recursion is one of the most key concepts we learned. I also learned that tracing recursion can be a bit of a hassle, but it really tests your tracing abilities. I would actually like to talk about how I used recursion with trees in one of the labs, but first, let me show you the code:

def arity(t):
    """
    Return the maximum branching factor (arity) of Tree t.

    @param Tree t: tree to find the arity of
    @rtype: int

    >>> t = Tree(23)
    >>> arity(t)
    0
    >>> tn2 = Tree(2, [Tree(4), Tree(4.5), Tree(5), Tree(5.75)])
    >>> tn3 = Tree(3, [Tree(6), Tree(7)])
    >>> tn1 = Tree(1, [tn2, tn3])
    >>> arity(tn1)
    4
    """
    if len(t.children) == 0:
        return 0
    else:
        c = len(t.children)
        for i in t.children:
            c = max(c, arity(i))
        return c

I know that this implementation of recursion is easy to do, but that is where the beauty of recursion lies. The beauty of recursion is in it's seeming simplicity. Using it, you can write what would normally be an ugly code full of loops in just a few simple lines. Checking a base case, followed by recurring. It can be hard to really appreciate what you are learning until you look back at what you have learned and see it in retrospect. When I first learned of recursion it was immediately obvious that it had great implications, but I couldn't appreciate those implications until I spent time actually using recursion and see how much shorter and easier it made some things.
    Anyways, I am glad I made this blog. It was insightful, and to anyone who is reading this; I hope you learned something from my blog!

-Anthony Arena

No comments:

Post a Comment