Sunday, February 8, 2015

Week 5

At very beginning of this semester, I talked to one of my friends who already took csc148 in 2014. When I asked her that how did she thinking of csc148, is it difficult? She said the recursion is very hard. Of course, I had no idea what recursion really stands for except that I think it a very cool name. Not until the last week, we finally been introduced to recursion. The starting introduction is very friendly because the example is dealing with the simple question--addition of numbers. we are given a problem at first, to sum a given list. The build-in function could easily solve it for us if the nest contains only integers. However, if the given list contains more than just integers, but a nested list, the build-in function 'sum' doesn't work for us anymore. I remember back to csc108, I used to encounter a similar problem that I need to sum a list where the list itself contains lists. for example, S = [ [5,6], [3,4], [1,2] ]. I remember what I did was to create a new list.
Apparently, this is very inefficient way of doing it, first it requires that each vector in the list much have same length 2, second it doesn't solve the case if the given list contains integers mixed with list, or list of list of list etc. Also, thinking about the running time, it's not the good way of solving such problems if we take the consideration of any of above we mentioned.

I don't who comes up with the idea -recursion, but when I first time saw it, I was very impressed that defining a new method in term of the method itself, functions can call themselves to solve smaller sub-problems.

So far, we haven't taught how to write a proper recursive function. All we do is trace each step. This part requires attentiveness and calmness so that we don't get upset and messed up when the given input is too complex. 

No comments:

Post a Comment