2015年3月1日星期日

Summary of Recursion

It's the seventh week I take computer science 148, the topic of SLOG today is to summerize about recursion, which we learned in last few weeks. 

Honestly, the first time Prof Diane talked about 'recursion' in class, I thought that it would be so useful if I had known this in csc108. To use the recursion would make the assignments a lot easier.

There is an easy example showed below:
to sum the numbers in [2,[3,4,[2,7,9,[[26, 16],34,67]],34]]

By using for loop or while loop, the code would probably be 10 or more lines long, and it's easy to make mistake on the complex loop.
In contrast, it's extremely easy to write a code in recursion form to solve this question. 

In my own opinion, recursion is like a huge loop which can keep running on each subelement of the given element till the last one. Similar with the mobius strip, the end of one loop in recursive code is the strater of another.

What's more, we were also told how to use recursion in the 'Tree Class', although I'm still not fully understand the 'Tree' structer. Since the recursion in that is quite complex, I believe it's essential to do more exercise and visializer on that.
 

没有评论:

发表评论