Friday, February 21, 2014

Recursion

By looking up the word Recursion in the dictionary, it means the repeated application of a recursive procedure. When I first saw the technique of using recursion, I thought it was amazing and kind of abstract. We have to break down something and go through each time the recursion works. For me, I think recursion is something we reused itself in the process. We create something while it exists in its own body. It is really hard to understand it for people who are not familiar with computer science.

I first saw this word in high school. I remembered it appeared on the math textbook in the sequence chapter. The recursion defines some kind of sequence where the sequence itself is neither arithmetic nor geometric sequence. Such sequence has the characteristic where a term is dependent on the previous term.

By using recursion, we can break down a huge problem into simpler problem and apply the same approach multiple times to ace a task. The process is going to end while the base case is reached.

For example, when we encounter a list of list, a recursive function is helpful to determine the largest value of this list of list object. Because the object is a list of list, we can crate a recursive program that works for a list and reused it for the elements within the list since those elements are just list. Here, a problem is reduced to a smaller one since the program is "recycled" and we don't need to create more steps to due with the elements inside the list. Recursion, again, suits for the big topic - laziness.

It impressed me when it is even being used in the Tower of Hanoi problem. We solve the problem quick and easy. If I were being asked to solve the problem, I think I will use much more moves to finish it, but with recursion, everything is being done in a few second. However, it is annoying when sometimes we don't recognize the situation for recursion. In the next few weeks, I must understand more about it and grab all the techniques and tricks of recursion.

See you soon!

Saturday, February 8, 2014

Cheese :(

Assignment 1 is due in a week! I started two week ahead and I am almost done. I am not a qualified programmer and Piazza is my best friend. Many fellow students throw a lot of helpful questions there and many of my problem are solved from the responses. The hardest part of this assignment is to figure out what the is should be because i will change once the recursion reduced. However, I am not sure if my way if proper, I implemented a function to find out the best solution and I used the equation in the assignment sheet to work back finding what the value of i is. I still use recursive function and it turns out working and giving me the best result. At this point, I don't think this assignment challenges me too much but I felt dizzy when i first looked at the sheet. 

In this week, we worked on recursion a few times. Let's write about it later in reading week. 

So far, I think 148 is more abstract that 108 and we need to practice to understand every concept. The lab is very helpful and I meet new friends every time. When it was in class, I asked the person sit beside me questions, and I learned a lot from them. 

Computer science is not my intention of coming to UofT, but from now on, I will consider it as my future studies. I hope I will make the best choice. 

See you soon! :)))))

Saturday, February 1, 2014

Inheritance and Exception (Week#4)

It has been a great week so far. This week, two important topics are introduced, inheritance and exception. We use inheritance to avoid rewriting some codes that have same characteristics. Professor Heap gave us an example on this topic. We have a parent class called Stack. It has its own methods such as push, pop, etc. And inheritance is introduced when a children class called IntStack is being created. Most of the methods are pretty much the same as its parent. We can create the children just by:

class IntStack(Stack)

and we can access the parent methods with Stack.method(...). This is really suitable for our first year goal - obtaining laziness. 

Another big big topic - exception, was 'raised' this week. We can create our own type of exception just by using inheritance:
XXXError(Exception)

We can raise one when something you don't want to see appears. However, when something wrong goes  into the program and you don't want the whole program to stop, an Try option can be built in the code. 

try:
    blah blah blah
except:
    blah blah blathe

The lab and exercise went pretty well and I hope I will start my assignment soon since it's busy these days.

Let's have a chat some time next week.