Thursday, March 10, 2016
Week 8 SLOG
The focus of week 8 was implementing class Tree. The terminology explained in the lecture slides was very helpful in understanding the concept of a tree. Two confusing terms were height and depth. After drawing some pictures of trees, I could understand the difference between the two vocabulary. Many functions in this class required the application of recursion. The codes for functions such as leaf_count, height, and arity were very similar to the material and examples we learned in class last week. However, using recursion for def __str__ and def __repr__ was hard to understand at first. By tracing through the docstring examples, I could see how to apply recursion in these functions. The trickiest part in creating class Tree was implement levelorder_visit. I thought that recursion must be used to implement this function like preorder_visit and postorder_visit. After implementing levelorder_visit using a queue, I tried to use a stack to re-implement preorder_visit and postorder_visit. By trying this out, I learned the power and helpfulness of recursion.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment