Friday, 27 March 2015

A review of 'Week 5: Tracing Recursion'

Looking back on my weeks in this course, I can honestly say that, for me, recursion ended up somehow being the easiest, the most difficult, and most interesting topic touched upon this year, all at the same time, and so I think it is most appropriate that I review my first impressions of tracing recursion.

One of the first things I notice about my initial impression of tracing recursion is that I immediately acknowledged that it was a complicated concept, but that I also found it to be fairly easy. I would probably attribute this to the easiness of the questions provided for us at the time, because since then, we have seen much more complicated examples of recursive functions, like the minimax algorithm. However, it is probably due to all the practice with tracing recursion we got that we were able to understand and even develop our own recursive functions. With this in mind, I can honestly agree with myself that 'it gets easier with practice'.

It seems that I was not the only one who initially found tracing recursion 'easy'. Ji Yong (http://148choi.blogspot.ca/) accurately predicted that while tracing it was easy, building recursive functions would be less so. The difficulties of recursion escalated quickly when it came to examples such as traversing trees, but once again, I must agree with my initial reaction, which was that everything is nice and easy once you find a way to reduce whatever is given to the base case of choice.

All in all, recursion is definitely a multifaceted concept, and I definitely did not see it being as complicated as it would come to be, unlike some of my peers. Perhaps I was naive, but now I know not to underestimate the power of recursion. On the flipside, the practice that we got definitely helped with my understanding, and as a result, I got a grasp on recursion rather quickly. Here's hoping we discover more uses for this fascinating concept.

Maximum recursion depth exceeded.

Saturday, 21 March 2015

Week 9 impressions: CSC148 - Introduction to Dendrology

I think that CSC148 should be rebranded as 'the study of trees', or, 'an intro to Dendrology', because by all that is good in this world, there are a lot of trees in this course.

This week focused on Binary Search Trees, which is a Tree ADT that uses only 2 child nodes per parent node so as to speed up searching through large amounts of data. Every node has a 'left' child and a 'right' child, and it is assumed that there is a distinction between what goes left and what goes right. The most common use for a BST was searching for a specific integer. In an integer BST, an initial integer is chosen to be the initial node. Smaller integers are placed to the left of it, and larger ones are placed to the right of it. This pattern holds for all nodes in the BST, and what you're left with is a tree that is organized from smallest to largest. This structure is helpful in speeding up searches for specific integers, since it eliminates either the entire left or right portion of the tree right at the beginning, and it cuts the search time by a hefty amount.

In fact, searching through an organized binary search tree is so effective that it uses logarithmic runtime, which means that the runtime of the search algorithm increases logarithmically as the number of elements in the tree increases.

There are, of course limitations. The BST has to be organized before you can use such an algorithm, so the data type isn't intrinsically efficient. Still, if we were to keep this in mind while creating a BST, we'd find that it is one of the most efficient algorithms we've learned thus far.

Thursday, 12 March 2015

Week 8

Linked lists are pretty cool. Not quite sure how we're gonna use them yet, but they are still pretty cool.

In week 8, we were introduced to linked lists. Its an ADT that does 2 things: for one, it stores data at at its nodes, and secondly, its nodes point to other nodes (unless you're at the end of a linked list), so you can traverse the list by following the chain of nodes that point to each other.

I suppose that focusing on linked lists was a welcome break from recursion, but my main issue with linked lists is that I have no idea what makes it more useful than a generic list. I mean, you can traverse a list in a similar way, and lists are already built into Python, so there's no added code required to work with them.

I'm sure this will be cleared up soon, but for now, I'm interested in the topic, but not sure how its useful.

Tuesday, 3 March 2015

Week 7 Impressions

Despair.

That's what week 7 felt like.

No, not the content being difficult. The assignment.

Assignment 2 has officially made week 7 one of the most stressful weeks of the year. You see, the concept of the assignment is simple. Implement Tippy, and then program a strategy that will always win at it. Simple enough, right?

Wrong.

When implementing the function for Tippy that determines if the game is over or not, I ended up making a function that went well over 200 lines. It looked like a gigantic lightning bolt because of all of the loops I implemented. When I showed it to one of my partners, he looked at me in disbelief, asking how on Earth a function could possibly be that long, and maintaining that there must be a simpler way to do it. We eventually cut it down to a reasonable size, but it took a lot of modification to make the function somewhat presentable.

Minimax is a whole other beast. Understanding the concept gets you nowhere if you aren't 100% confident with how you're implementing it. One problem we had to avoid is an aliasing problem. When we broke down the initial Tippy gamestate into all of the possible gamestates, it altered our original gamestate and filled it with 'x's everywhere.

It seems like we still have a lot of work to do.

Tuesday, 17 February 2015

Object Oriented Programming

Ah, Object Oriented Programming. I remember when you were as simple as programming a virtual cash register in CSC108.

The way that Object Oriented Programming was explained to me is that its nothing more than Class Design, at least for the purpose of this course. Originally, class design was one of the topics that I understood the least in 108, but it ended up being the topic I understood the most by this point in CSC148. The concept of class design is simple, at least in my opinion; you create a name for some sort of data type, you determine what variables (usually numbers or lists, at least in this course) are associated with it (usually in the __init__ method), and finally you create an array of functions which perform operations on those variables.

Object Oriented Programming is incredibly useful, because while Python has many different kinds of objects already built into it, it is limited to a handful of general objects, such as integers, strings, lists, etc. With some clever class design, a programmer could implement games, create different data types, and do much more, where they otherwise couldn't using only built-in objects. Working on assignment 2, my partners and I, for example, are adding a game, Tippy, to our already existing game classes. We initialized the board the game is going to use, and we are adding in functions to add moves to the board and to represent them visually to the player.

All in all, OOP is a good way to tackle problems which deal with a central piece of information, like a game board or the contents of a cash register. I'm interested in seeing the many ways we will use OOP in the remaining weeks of class.

Edit: Evaluate this one.

Thursday, 5 February 2015

Tracing Recursion

Tracing recursion seems quite mind boggling really.

Think of it this way. There's a base case, where a simple input to a recursive function returns a simple result. This base case is there for two reasons: the first being to trick the tracer into thinking that recursive functions are easy to trace, and the other being that the way a recursive function works is by reducing complicated inputs to that base case.

So what happens if a more complex input is used? Well the recursive function takes that input, performs an operation on it to return a result, takes that result, and uses that as the next input for the recursive function.

Wait, what?

Yeah, it sounds complicated at first, but with a piece of paper and pencil in hand, it becomes rather fun to trace. You basically just keep calling the function until you get to, you guessed it, the base case, and then you pray that the function stops somewhere.

Trust me. It gets easier with practice.

Friday, 30 January 2015

Impressions of my first few weeks

In my first few weeks in this course, I've found that a lot of what we have been doing has been review of CSC108, with recursion just being added in now. I found that the review was very helpful, since Class Design was by far my worst topic in 108. For the life of me, I just couldn't understand how to use inheritance in any significant way, but through the labs and through work on assignment 1, I quickly understood that inheritance was a very useful tool, especially for lazy people like me.

Assignment 1 helped me realize that when dealing with a problem, the superclass is a general framework which is then aided by the subclasses, which is where the specifics of a problem are worked out.

Being a hands on learner, I have to applaud the designers of this course for appealing to all kinds of learners. I'm sure that the lectures are really useful for people who learn by watching, whereas the assignments and tutorials are helpful for people like me. That being said, I am very pleased with the depth of the review, and can only hope that future topics will be handled in the same way.