This week, we have learned how the Tree Class works and how to write some recursive function based on Tree and Queue.
Actually, I did not know the function descendents_from_list before lab this week. I'm so thankful my Ta of our lab, he told me that descendents_from_list function is a function to build a tree based on the arity. For example, the tree descendents_from_list(Tree(0), [1, 2, 3, 4], 2) is a tree starting with Tree(0) and listing the 2 nodes which is the same number as arity from the first two elements of the list; thereby, the 2 nodes will have the same number of children as arity if there were enough elements remained in the list. In the situation of descendents_from_list(Tree(0), [1, 2, 3, 4], 2), the tree starts with 0, two nodes tree 1 and tree 2, and tree 1 has two nodes 3 and 4.
Furthermore, in the lab exercise, I learned how to write a recursive function more deeply compared with last week. I know when the function called itself, it would start a brand new id location to store his value used in function body, and we need to 'building a place' to store the total useful value when we ran it.
I'm expecting next lecture! By the way, I feel recursion is very interesting and will be very useful in the further study.
No comments:
Post a Comment