Matrix

Saturday, 28 February 2015

Week 7: The Return of Recursion

So as reading week ends and class starts up again, we are told to write a summary about a key concept that we have learned. I chose recursion because I struggled with it in labs and on the midterm so naturally I studied it the most afterwards. 


So what is recursion exactly and why is it important to computer science? Recursion is a type of method in computer science where a function is able to call itself to solve smaller instances of the same problem. The opposite style of code to recursion is the generic iteration style that we used throughout CSC108. Iteration is looping through a block of code until it solves the problem. So recursion is sort of like a type of iteration. There is technically no real need for recursion. Everything you do with recursion can be accomplished with iteration through loops. The real benefit to recursion however, is that it simplifies things when you must run through a lot of code and it cleans it up in an "elegant" way. This makes the program run faster and becomes more easier to look at and understand. For example in class, our professor was able to cleanly go through complicated lists with many brackets by using a recursion function. This saves a lot of time and makes "traversing" through complicated code a lot easier than iteration. 


In class, there have been several examples of recursion use in Python. We have not written any of our own recursion as of yet but merely trace the code in order to understand the core idea of recursion better. Most examples include complex, nested lists and ask for the result when a recursive function is run on them. The labs offered more practice with tracing recursive functions and although tedious, they offer practice which is valuable in understanding recursion. In general, I think the concept of recursion is very hard to grasp at first. I found the entire concept behind it to be quite foreign to me. You don't understand how it works by calling itself while you run it. This is why tracing the code is so important for practice and understanding. However,with practice, it becomes second nature to simplify your code and understand how each line is being run. Ultimately, that saves a lot of time down the road when you include complicated inputs. Learning recursion is absolutely vital I think so it is great that I took the time to learn it. It will help immensely in the present and future. 

Friday, 13 February 2015

Week 6: Trees, Branches, Forests, and Reading Week

It's the 6th week of CSC148 and that means it's the last week before reading week. This week's focal point was on trees. We learned some basic terminology and how trees worked within a program.

Not exactly like these trees per se.
The most important use of a tree is that it can be used to represent hierarchical relationships. This can be the structure in a program, relationships in an mathematical expression or directory structures. In programming, trees are an ADT (abstract data type) which consists of a root value and several subtrees linked by nodes.
A visualization of a tree used in programming.
Our professor did an interactive example during our Monday lecture. She made the student in the back row of the class stand up and he became the root of the tree. He would subsequently point to two other students in the next row to stand up and those students would point to two more students and so forth.

We studied this further in our labs where we would implement recursive functions when the input was a tree. Trees seem relatively simple to understand but the core concept behind recursive functions and how they work is a must. I struggled with recursion the past week but I was able to catch up and understand. Now, trees are a relatively simple concept to grasp.

Friday, 6 February 2015

Week 5: Introduction to Stacks and Queues

This week did not include a lot of lecture time. On Monday, a huge snowstorm snowed in many people and our professor was late as a result. Wednesday was the first term test so there were no lectures then. The term test was fair and it was easy to do well in if you studied for it.

On Monday, we looked briefly at unit tests and how they work as well as a breif description about stacks. There wasn't much detail since a lot of the lecture was missing as a result of the storm and with the term test coming up, most questions revolved around that.

In Friday's lab, the focus was on stacks and queues. It focused on practicing with stacks and queues and seeing how they work. We also focsued on the efficiency of queue implementation and how it would affect our code. This week was easier to understand in comparison to recursion but it was still valuable information to know about. Knowing how stacks and queues work make your program more manageable. Arrays and lists are random access and stacks and queues allow you to manage your data in a different manner.


Matrix