Monday, March 2, 2015

Week7: Recursion in Trees



Hello, week7! This is the first week of the second half of the semester. It is a really busy week as it’s the first week after the reading week. I’d like to write something about recursion in this week’s slog.

As I mentioned a lot of times in past slogs, recursion is a significant and challenging topic. Tracing recursive methods was quite simple; however, writing my own recursive functions is difficult. In last several weeks, I got to learn about recursion in trees, binary trees and search binary trees. Tree is a way to store data in its root and other nodes. We can implement methods according to tree’s attributes like height and depth.

The general approach to implementing a recursive function is choosing cases wisely to represent various possibilities of the result. The simplest case is known as base case, which is a case that we don’t have to use recursion in it. However, based on this base case, we are able to write more complicated expressions to deal with more complex cases. Recursive functions call the function repeatedly until the base case is reached. And then return the result back to the previous step. One of the biggest advantages of recursion is that it breaks an undoable problem into small pieces and adds these pieces up to get the final answer.

                                                          This is a general form of recursion.


After mid-term, I have encountered more recursive functions both in labs and assignments. To be honest, it’s tough for me to come up with the code. Although I can figure out the base case, I still couldn’t come up with the recursion. So I discussed it with my partner and turned to TA for help. These resource give me some different views on it so that I think up some different ideas about it.
 



No comments:

Post a Comment