Sunday, March 1, 2015

Summary of Recursion

    After familiarizing myself with the abstract data type Tree and recursive laboratory exercises, I finally have a basic grasp on reading and writing recursive functions. Recursion in terms of programming is a technique that breaks down a complex problem into very basic but also very similar problems in order to solve a problem. In essence, it involves writing functions that call on themselves inside their function definitions. Generally speaking, recursion contains a base case that will most certainly be visited at least once, and also one or more general cases that breaks down the problem and directs it to the base case. The SLOG posted here at http://148blog1.blogspot.ca/2015/03/recursive-code-and-advice-on-how-to.html provides a detailed explanation and tracing of the function sum_list that is of recursive nature. I agree with the author that recursive code allows for efficiency, whereas iterating through a problem can often become very time-consuming, or even impossible for some cases.
    Writing recursive code isn't exactly a breeze. In my previous post I said recognizing the base case means almost solving the problem, but that was not true when I encountered problems involving the abstract data type Binary Search Tree. I was hopelessly lost even after recognizing the base case, because the recursive code actually contains several general cases, such as when the value is greater than the float data rooted at 'node' or when the value is less than the float data. The question was considerably more difficult for me because it wasn't clear what to do once I figure out the base case. Then, I presume there must be many more types of problems that involve some variations of the basic recursive code for sum_list, where the base case does not clearly provide a hint to the next steps, and I think the key to solving these problems is a thorough understanding of the problem and some creativity.

No comments:

Post a Comment