On week 7, I've learned what is a Tree class and a binary tree which is a type of tree with only two branching factors. A binary tree usually has children called left and right child.
In the lecture, we use a BTNode to study a binary tree. This BTNode class is a binary tree that left children in each node(can be viewed as a parent of a subtree) is smaller than right children in that node. What I need to do to understand BTNode first is to understand the functions in the basic Tree class.
contains(t,v): is used to determined whether the value v is in the tree t, or the tree t may has no children and whether value v is eaqual to tree t itself.
height(t): is used to tell users the height of total tree. What we should know is that the value of height of a tree is equal to number of branches plus one.
descendents_from_list(t, L, arity): is to populate tree t's descendents from L. Arity is a integer which tell users the number of children of each level node.
In BTnode class, we learned how wo add children or new node in Tree. Visiting each node and do something at each node is called traversal. In-order traversal is to visit a node between visiting its two children.
To finish lab06, we need to know the job of is_leaf(node) function and how to use it. is_leaf(node) function is a helper function to help each function to determine whether Tree has children or not. If the tree node is not a leaf, we can use recursion to help each function run to get final result.

No comments:
Post a Comment