Saturday, 7 February 2015

Week #5 --- Impressions of tracing recursion from week 4

   Recursion, What is that?! When I first saw the function has the name of the function within the function itself, my immediate first impression was just 'How is it going to work?'. It looked really weird at first sight! Gladly, Professor Danny explained to us step by step what recursion is about and what kind of problems we can use recursion to solve.
    Basically, recursion is an algorithm that you plug in the name of the recursion function into the function itself for certain conditions with some other elements in the function for 'other' conditions, so when an argument is processed, it will either meets the 'other' conditions and be directly executed, or be broken down into pieces, and those pieces will be processed through the same recursive function again until they meet the specific 'other' conditions.
 
    For example; We have a deck of one hundred random poker cards, and we are to find the joker card in the deck. It's really gonna take one person some time to find it, but with recursion, we may break the one deck of one hundred cards into ten decks of ten cards, and have ten people looking for the joker card the same time, which would be a lot more efficient, or we may even break the ten deck of ten cards into one hundred decks of one card and have one hundred people just checking their only one card the same time. In this way, We will be able to find our joker card in a blink of eye! Now, that's the beauty of recursion! It is how we can break down one fairly complex problem into many pieces and solve all those little pieces individually. It can just make our codes a lot more efficient!

    I found the tracing of the recursion in class to be quite helpful. It taught me the idea of how the recursion break down and go recursively, and how is the recursion function working when we do it on a computer. Same thing for the ones in lab, those tracing of different type of recursion functions introduced me to a variety of how we can use recursion to solve different types of problems, so recursion came to me as understandable and it did flow quite well in my mind, but it was no longer the case when I had to write recursive functions myself. For the last question in week 4's lab, I was stuck on it for almost half of the class, and I couldn't really figure it out until the TA gave me some obvious hints. At that time, I realized that my mindset of writing recursion function was wrong. I tended to think about the huge amount of the broken down pieces at the end, and that was just highly inefficient, because I really didn't have to. All I should have done was to think about the base cases when there will be no recursion and the argument will be directly executed, and the recursive cases when the function needs to break down the argument into many more pieces, then carry on to how I can develop the detail of the function based on what the function's about.

    Now I feel that I'm much more adapted to the writing of recursive functions, and I'm really looking forward to how I can make use of recursion in the future.



Here is another explanation of recursion from another slogger



No comments:

Post a Comment