Hi, everyone!
We had two lectures about how to represent binary trees in Python. Since I am taking csc240 now and we just covered this topic, it should not too challenging to me. I think the nicest about binary trees is that it is a great example for doing recursion since a parent tree can have two children and then keep continuing. If we know something about its subtrees, let's say leaves, then we know the number of leaves of the whole binary trees.
The prof covered three examples of how to order binary trees (preorder, inorder postorder). All of three functions involve recursion, and I find it really helpful to run the recursive functions in Python visualizer. It can help you understand recursion better.
Also, the prof talked about Tree class, the most interesting of this class is basically all of its method involve recursion. So when the prof wrote the method, I experienced a hard to follow him. But I did review all the methods at home and had a better picture of this class. Besides, I learnt some new build-in function of Python. For example, any function can return True if one of the element in for loop is true. And filter function is a good idea to combine another function result and a for loop to produce a list.
Anyway, term test is coming and next week is reading week. Hope it would not be an actual 'reading' week.
the description of binary tree is very clear!
回复删除