Sunday, 2 March 2014

Recursion

Recently, I read a tutorial on recursion, yet there was something special about how the author explained it. He used zombies and humans to try to explain it. The idea was that zombies bite humans and those humans turn into zombies which bite other humans. Specifically, this was a neat chain reaction. That is all recursion is. A chain reaction that occurs and keeps going until it stops and then the end result is usually what matters. In the zombie case, it keeps happening until all the humans turn into zombies.

I think recursion is a topic that everyone will fully appreciate as we continue through the course. The depth of it's usage and usefulness is tremendous. It is very useful in algorithms that feature mathematical calculations that are based on the result of the previous calculation. For example, the Fibonacci sequence can be expressed as an algorithm. Even something very simple such as manually calculating factorials. 

We, as a class make recursive calls through list comprehensions almost exclusively. I have yet to see an example on the csc148 website nor the examples in class that feature recursive calls that are not in the return statement. Personally, I have trouble understanding the list comprehensions because I am used to writing multiple lines of code rather than compiling it all together in one big return statement. But that is just my opinion.

I definitely think that more practice with recursion would benefit me even though we do not go over the topic much anymore because of how useful and practical it is in creating self propelled projects.


Sunday, 16 February 2014

Trees!

This week in CSC148, the topic we covered was Trees. Trees are a very interesting data structure that is very useful in computer programming. It is made up of series of nodes which contain data. Nodes continually store data like branches in a tree until they reach the endpoint, which is the leaf. The leaf has no more children.

The Tree data structure uses a lot of what we previously learned. A big part of this is recursion. We use recursion a lot, especially when we are traversing through the tree. There are three types of traversal. Post, Pre and In order traversal. I find it very easy to differentiate between them by remembering that one is-
left top right, right top left and top left right. By using this it is easy to make the traversal be understood.

In other news, the midterm is coming up. I have to say, it is quite scary to think about it. I am particularly worried in forgetting the simple syntax that we learned. Usually when i code and forget about a specific function, I have the option in looking it up. If the English language is proving difficult to understand, I could always type it in the shell. In the test, I do not have this luxury. Therefore, for me, it might prove difficult.

Sunday, 9 February 2014

Tower of ...Cheese?

Well out of all the simulations that could've replaced rings in Towers of Hanoi, I don't understand why cheese was picked. Moving cheese around? Not very realistic. Even so it sounds interesting. The Tower of Hanoi is a famous math puzzle designed to help understand recursive solutions better. The last time this was explained to me, I( along with my group) were tasked to solving it using an iterative solution. By doing it recursively, it made things more interesting. Tower of Anne Hoy is almost exactly like Tower of Hanoi except with an extra stool. With this extra stool, solving it will be a bit more challenging.

The lab this week was also interesting. It was unlike other labs because the first few minutes were spent on tracing functions. I guess this was to brush up on our recursive functions but I thought it was too simple. The next parts of the lab were quite up to standard.

Next week we finally do trees. (Yay!) I am looking forward to it because I had trouble with it in the past. I used to think that values to the left are always smaller than the root and values to the right are always larger. I am not quite sure why I was under this impression but because of that, it made it difficult for me to visualize trees and the concept of them

Saturday, 1 February 2014

Inheriting recursively except when not

When we learned about inheritance and exceptions, I thought it was grade twelve all over again. Almost nothing has changed over the course of the year when it came to these topics in python. These problems are solved the exact same way as they were in Python 2.7, which I am quite familiar with. However, the first term of 108 was spent on very basic things(NOT Object Oriented) so inheritance was a good refreshing of memory. Because of such a long hiatus in using classes, I was quite pleased with the review of the syntax.

For me at least, recursion isn't exactly new either. That being said, the python language Danny is teaching is not too familiar to me and the extensive uses of list comprehension is quite extraordinary. Many examples were simple 1 line answers instead of the multiple nested loops that I'm used to. I guess this is being efficient, but pythonese is truly extraordinarily simple compared to the language of java. System.out.println was really a headache because of the lack of connection to the coder. Print(x) is much more simple and easy to understand as it shows a clear indication on what the code will do.

I had learned recursion in my previous year in high school as well. However, I did not put it into practice a lot since we were just mostly taught the theory behind it. It was nice to see a lot of practical uses that recursion had.

I am looking forward to next week's lectures where we hopefully continue learning about data structures, a more abstract view of computer science. I find this very interesting. I mean, recursion is cool and all but learning things the second time just isn't the same.

Thursday, 23 January 2014

OOP-in short

Object Oriented Programming. Well, it would be a lie to say that I found the subject enjoyable. To tell the truth, this is the fourth time learning about it. Classes have been drilled into my memory to the point where I have thought the application to the real world; that is, if life was a computer program. Although, there were still new things that I haven't learned. For example, embedding the docstring into the parameters of the class was unfamiliar to me. 

In the tutorial this week, we did a fairly simple assignment on stacks and on queues. The last question however, was quite puzzling. This is because the solution to the problem no longer renders it a queue. This is because the list never removes the first element, it just shifts to the next element. I thought queues would be similar to line-ups, in which people enter the line at the end but are served at the front. In this situation, the people who get served never leave the line. I found this solution to be misunderstood, because although it behaves like a queue, it isn't actually a queue. 

All in all, I am just waiting for the course to pick up. Hopefully this happens soon because object oriented programming isn't very challenging, which I had hope this course would deliver.