Sunday, March 1, 2015

Week 7: Recursion: Fanciest Stuff I Have Seen

Week 7: Recursion

First Sight

I can still remember, the professor introduced the idea of 'recursion' several weeks ago. At that time, I thought it was a piece of cake. It reminded me a quite famous story from ancient China: "There was a temple in a mountain. In the temple there were two monks. The senior monk told a story to the junior monk: 'There was a temple in a mountain. In the temple there were two monks. The senior monk told a story to the junior monk: 'There was a temple in a mountain. In the temple there were two monks. The senior monk told a story to the junior monk: ...''". Yes, the story never ends. That's my first sight of recursion: something that repeats and repeats and therefore it never ends. But how is that different from 'while-loop'? Is that a 'while-loop' in a class?? These questions triggered me to keep on struggling on computer science.

Difficulty

'I should have prepared for the lab!', that was what I thought after the lab about recursion. Normally, I didn't need to preview for the contents of the lab. Still, I could comprehend most of the knowledge points hidden in the lab and get a 2/2 in the quiz . But it was the first time I could not finish all the questions in the lab! Even for the first question, I had struggled for a hour (Every lab is 2-hour long.). I only finished half of all the questions and I messed up the quiz! What a shame! I became frustrated and sometimes I even thought computer science was not suitable for me. But I am not the person that give up so easily.

Struggle

I began to listen carefully to every word that the professor was saying. I began to ask questions in the office hours and on Piazza. As a result, I began to comprehend the essence of the recursive functions: Functions that are using and are used by itself. And I found a 'trick' to write recursive functions:

if <first example>: # Usually it checks for the empty case.
    return <the type defined in the function>
else: # The second - last examples fit here.
    <use the function itself: where the recursion goes>
    return <the type defined in the function>

Maybe it is not a trick for somebody. It is simply a stardard format to write recursive functions. But it really helps me a lot.

Epilogue

I become more confident with recursion now. I could easily recognize how the recursion is hidden in the question though some questions still struggle me for a long time. I have boundless thoughts about recursion but I have to finish my assignment about recursions now!

No comments:

Post a Comment