Before we were told that this week's slog topic is recursion, I wrote about recursion in a previous slog entry.
This is the URL to the previous entry:
http://ehslog.blogspot.ca/2014/01/first-taste-of-recursion.html
Today's entry will be based on the last entry because I don't want to repeat too many of the same things.
As previously mentioned, I find recursion new and interesting. My understanding of recursion, method wise, is calling a function within the function itself. Purpose wise, is to cut the problem down into smaller problems that are easier to solve.
I remember an analogy that I came across during the period when I still couldn't grasp the concept of recursion. The analogy was about a stack of chairs. If you had 99 chairs to move, you will first consider moving the top 98 chairs, then consider moving the top 97 chairs, and so on, until there is only one chair to move, which makes it much feasible than moving 99 chairs at once.
This analogy outlines my understanding of recursion.
I think recursion is useful when a problem can be narrowed down into smaller pieces. Also in situations such as nested lists, we saw in class how recursion makes it easier.
没有评论:
发表评论