Sunday, 8 March 2015

week #8 : impressions of week 7

In week #7, we continue learning tree. Instead of general tree which is the new knowledge taught in week #6, we learn a particular kind of tree called binary tree as well as the node class for a binary tree. A binary tree is a tree which only has two children called left children and right children. The binary tree can be easily understood once we got the idea how a general tree works. However, some functions under a binary tree class including contain function is a little bit different from the general tree class as we have to make it more specific into left and right children rather than just children.
Here is the contain function in a tree class:

And here are the contain functions in a binary tree:

All of them use recursion: first assume that the function contains works, and then make it to a helper function into the code itself. The only different is that writing contains function of a binary tree, we have to think both left and right children not like that in a tree class.
Overall, I think the tree class is interesting and is pretty helpful for us along with the recursion. Once we understand them and know how to use them perfectly, it will be our treasure in future studies.


No comments:

Post a Comment