Sunday, March 1, 2015

Week 7, summary of recursion

    As the reading week went pass by, I am overwhelmed with things coming at me not prepared (since I wasted my reading week doing nothing). Some few things that bothers me these days are midterm 2/finals incoming, and my computer science assignment which I haven't started yet (I blame myself). Talking about the assignment due next week, most of the hard methods we are writing this assignment requires the use of recursion.
    My first interaction with the word recursion is when a few of my friends complain to me about how hard and abstract recursion is. So when I am studying computer science and when we are at the concept of recursion, it sort of gave me a "fear" and "excitement", but it turns out that recursion is not that hard at all. The "trick" for me in learning recursion is to only think one layer at a time, because recursion can be very logically tricky when we try to think it as a multiple layer.
    A recursive function consist of two parts, a base case and a recursive case where the base case (can also interpret as a terminal case) is a case to stop the function, for example if we are trying to write a recursive function for a maze solving problem, the base case can be when we got to a dead end or when we reach the exit.
    A recursive case is the part that made recursion so powerful, the recursive case splits a hard problem into similar but simply case and the function will keep calling itself until all the "simple" case has reached to it's base case. For example, if we use the maze problem again a recursive case for that would be checking what will happen if we go left, right, up, and down, and if we move left, what would happen if we go left, right, up, and down, and so on. Did you notice the power of recursion? We can solve a very complicated problem which requires a possible run time of n (where n is the max(length,width) of the maze) into a few hundred line of code.

No comments:

Post a Comment