Saturday, March 7, 2015

Week #8: Binary Trees

Week #8: Binary Trees


We have learned binary trees in the last week lectures. Although it is a new concept we need to care about, we can see quite a lot of similarities between Trees and Binary Trees. Binary Trees are just simpler Trees, for there are at most two children from the root node. But it may be sometimes much more useful than an ordinary tree. 

First we can take the root as a operator, then we can do some calculations between operands. Second, which is more important called binary search tree,  is used to reduce the unnecessary steps in our recursions. For it has the properties that:

We can promote the efficiency of the recursion by compare the requirement with the left nodes and right nodes, which results to a faster searching speed. And also when we write the binary recursions, we need to focus on the sequence of adding the item to the result and the comparison of left and right nodes.

Just like we have done in the tutorial:
This list_between function can be considered as a typical of binary search tree recursions. As an ordinary recursion, we have both base case and recursive case to consider. The base case is sometimes simply referring to the leaf node case, which means the node has no children, while in this function a none node need also be kept in our mind. In the recursive case, we need to notice what the sample solution want to inform us. One is the utility of the properties mentioned in my last paragraph, i.e. saving time doing searching. Another is the sequence when we add up the result coming from the recursion. 

To sum up, the core idea has not changed from tree structure to binary search tree, but when we implement the binary tree functions, we need to keep an eye on the sequences and comparisons.

No comments:

Post a Comment