Saturday 1 March 2014

Recursion

After taking this week's term test, it's becoming quite clear to me that recursion is something that is not only extremely useful for computer programming, but also crucial to writing efficient and concise code. Being able to recognize where recursion can be implemented when writing code can save not only a lot of time, but also cut a lot of superfluous lines of code out. It is also important, however, to recognize that recognition of the potential to implement recursive code is not enough; it is more important to actually be capable to writing recursive code as well. Personally, I have not quite yet grasped this skill but my recognition of it's value has definitely persuaded me to review recursion intently. I hope that we are provided more opportunities to practice writing recursive code prior to the final exam as improving my ability to write recursive code is definitely something I hope to achieve by the end of the course.

Saturday 8 February 2014

Recursion - The Complexity of Simplicity

After this week's lecture on recursion and having learned about the recursive code for solving the tower of hanoi problem, I found myself fascinated by the simplicity of the code. Personally, I found it astonishing how such a small amount of code was capable of solving the tower of hanoi problem given the fact that the number of cheeses involved could be infinite. Although understandably the tower of hanoi is perhaps one of the simplest problems solved with recursion, I feel as though it is quite an eye opener, as it exhibits the immense capabilities of programming and the limitless potential of computers through simple yet complicated processes such as recursion. Learning about recursion has inspired me to motivate myself into doing extensive research when confronting future programming problems and assignments; I believe that in doing so I may just stumble upon things such as recursion which I hope to share with those who may not know of them. This has also served as a reminder to me that it is important to always keep in mind that "laziness" is key to being a programmer and that perhaps it is indeed true that simplicity is bliss.

Thursday 23 January 2014

Object-Oriented Programming

During this week's lab, after seeing the inefficiency of the queue class functions I wrote in comparison to the stack class functions, I couldn't help but do some further research. From my research I was able to find the primary factor contributing to the inefficiency of the queue class; with each and every dequeue, every element after the first in the queue list must be shifted in order to maintain the list. As a result, I witnessed a linear correlation between the time taken for a fixed number of items to be queued and dequeued and the number of items in the queue. With lists alone, I was unable to come up with a solution for this problem during the lab, however during my own time I came across a plausible solution: the deque (pronounced "deck").

The deque (short for double-ended queue) supports memory efficient appends and pops from either side of the deque with no substantial difference in performance regardless of direction. Previously, using Python's built-in list to create the queue class resulted with the program struggling when it had to dequeue an item from a large queue. But by using a deque, the dequeue function bypasses the struggle as it does not have to shift every item in the list to maintain it after the first element is popped. Personally I found the deque to be quite intriguing but my discovery of it also got me wondering as to why it shouldn't just replace the traditional built in list entirely. If you share my interest you can find more info on the deque and its methods here.