Thursday, 20 February 2014

SLOG #4: Trees

Last week, we didn't learn anything new. However it's still very helpful since we applied knowledge from before, especially recursion, to build trees. A tree is a good example of a recursive structure.

We firstly learned some terminologies about trees and found there are three different ways of traversing a tree: preorder, inorder and postorder. It's quite useful to learn how to write functions for these traversals. I found these functions are the same in base case. The only difference is the order of the functions in general case. The advantage of applying recursion is obvious here because it is easy to read what is going on in the function.

Code for general tree implementation is a little bit hard for me to write at the very beginning. After Professor Danny showed us the answer, I felt things become easier and I started to get used to the tree structure. Through practise, I feel it's efficient to think about several easy examples, write down the base case carefully firstly and then to introduce it to general case.

The midterm is coming next week. Good luck everyone :)

No comments:

Post a Comment