2015年2月9日星期一

CSC148 WEEK 5



I actually wrote about recursions last week, but I suppose I will write it again just to meet up with the topic. The concept of recursion is very interesting and useful. By allowing functions to call itself, many sophisticated problems can be solves this way.

The most astonishing fact I find about recursion is that it is able to conduct an infinite number of computations with a finite statement.I also find it astonishing that how recursion is able to solve an apparent logical paradox. The paradox is that whether the method is defined before it is called within himself? Or does it exist after the return function?

For instance the method sum_list(L) is written as follows:

def sum_list(L)
  if isinstance(L, list):
     return sum([sum_list(x) for x in L])
  else:
     return L

So is the method sum_list(L) defined in the second line of the code when it is called? If it's not then why wasn't the function producing an error? If it was then what is sum_list before it is even defined?

It is interesting how the computer was able to operate under such paradox, and still produce a result.

The application of recursion is almost everywhere in the world of computer science. For instance, we are about to learn the class tree which will extensively use recursions. I am looking forward to that!

 Many of my peers found recursions to be hard. I find it easy. This is perhaps because I have strong mathematical background, and recursion is a concept that is more closely related to logic than programming. The harder part for me is probably the programming part. I am falling behind in programming because I didn't study hard for the first couple weeks, and I better catch up soon! 

Also, I find the test to be particularly hard. I came from the evening session and everyone said it was hard. Mean while the morning session thought it was easy! This is so unfair!!


没有评论:

发表评论