Sunday, February 16, 2014

Week #6

This week I finally grasped the full extent of how useful TreeLists can be. I was reading over treelist.py which was posted last week. I knew it might be on the midterm during the week and so I read over it, and fell against an old enemy of mine: recursion:

def inorder(tl: 'TreeList') -> list:
    """
    Return a list of values of tl inorder

    >>> inorder([5, [4, None, None], [3, [2, None, None], [1, None, None]]])
    [4, 5, 2, 3, 1]
    """

    return ((inorder(tl[1]) if tl[1] else []) +
            [tl[0]] +
            (inorder(tl[2]) if tl[2] else []))

The return statement basically parses a recursive statement for elements prior and another recursive statement added to end. It took me a long time to understand it as for me I understood the base of inorder going over the method for each element but was very confused as to why exactly this happened. Wrote it down as a question to hopefully ask Danny during office hours or a TA or a classmate.

I learned something new in the form of TreeList, I knew what they were and would be able to visualize it, however writing them down as code was a different challenge. Using posted codes and resources (such as Coding like a Pythonista) I was able to get a full grasp. Also have a bunch of Youtube videos just waiting to be watched that explain in different ways. I get the general aspects of it, I struggle however with its implementation with recursion.

Recursion keeps on challenging me and frustrate me. I feel like I am a very logical person, I love understandings the crooks and hidden aspects of things, however, the logic of doing a 'leap of faith' has me all mixed up. Hoping to get it soon, won't give up on it.

Interesting SLOG of the week:

http://lavendercsc148.blogspot.ca/


For Week #6 Lavender broke down the Assignment 2 which was due the previous week, with this blog entry being the first part (part 2 also discussed in my Week 7 SLOG). While part 2 focuses on the regex_match code, this week is all about the __init__ required for the Assignment. She talked about where she had difficulties which coincided with mine, however she found a better solution (lucky me!!! (<- really hard to convey sarcasm over the internet)) and used a helper function which I should have done...

Sunday, February 9, 2014

Week #5

This week I've learned about nested list recursion and how to implement them inside methods. I also struggled with the first assignment, I kept getting an error that would only show on IDLE whenever I'd execute the PyGame module, stopping me from seeing any listed towers of cheese. I spent a lot of time going back to old notes in order to get a fresher point of view in order to do the assignment. I am also preparing for the midterm at this point.

Recursion has been my greatest challenge, it took me a very long time (and I still struggle with it) to grasp the more difficult uses of recursion. I understand the concept very well and am able to solve simple methods easily but I need to deepen my understanding on how recursion works exactly.


Interesting SLOG of the week:

http://veraslog.blogspot.ca/

Quite a gem of a blog I found this week with each entry being bulky (not in a bad way) and rich in details. Vera (I'm assuming) answered the question assigned to us by Danny about recursion and OOP( object oriented programming). He/She wrote such a great definition for recursion that I need to post it here:

"Recursion is an unusually simple but difficult concept to grasp. It’s an extremely efficient way to handle certain situations but is often neglected or overlooked. My programming teacher in high school always said “You either understand recursion or you don’t. Usually it just hits you one day and you get it”. The “What is recursion?” question is regularly asked by programmers. If you search on Google, you get a variety of answers ranging from “Recursion is a method where the solution to a problem depends on solutions to smaller instances of the same problem” or “Recursion is the process of defining a problem in terms of itself”. In other words, recursion is a function that calls itself a number of times.  It is important because it allows programmers to efficiently solve a mathematical model/algorithm that has definite boundaries/parameters. There are a variety of examples where recursion would prove handy such as; traversing trees, modelling mathematical formulas such as factorials (our Towers of Hanoi algorithm too!), fractals, etc. Recursive functions are usually easier to read and understand than solving with loops. Other benefits are that it’s simple, uncomplicated, and time-efficient as opposed to loops."

Sunday, February 2, 2014

Week #4

This week I've learned about recursion and how to implement them inside methods. I enjoyed learning about them as it gives a whole other side to programming. By using recursion it's easy to think of many ways to shorten methods and files as a whole.

Testing sounds simple in concept but way harder when it comes to remembering all the syntax. My achievement for the week was to get the hang of Stacks as it was a hard topic for me in the past weeks. Tutorial went well but I couldn't finish the handout on time.

By using Recursion it is more easily feasible to solve problems that involve subproblems. Nested lists for example or whenever we need to reiterate over an object/list/etc. However, I've been having a lot of difficulty trying to understand exactly how to take the leap of faith.

I understand the basic principle of having a base case and then implementing the recursive statement but for complex ones I always seem to get confused. I will make sure to ask more questions to my TA and see how I can improve myself.


Interesting SLOG:
csc148.com (a self-host nonetheless)

This Slog has to be the prettiest slog available on the whole SLOGs page for CSC148 (I won't lie and say I've been through them all but I am fairly confident I've at least opened half of them). The style and presentation alone make me want to read the Slogs. The Blogger talked about recursion and OOP (topic for next week) but I couldn't help but just admire his blog. Really, it's amazing, whoever is grading this/reading this should definitely check it out (here's a link to the specific slog I'm referring to LINK)