This was the last lab of the course, and a very interesting one. The goal was to create a "complete binary tree" which is simply one where each node must be inserted in the left most spot on the tree. One implication is that all "levels" (or nodes of the same depth) must be filled except the last one, and that the entire tree can therefore be distinctly represented by a list. To parse a list into such a complete binary tree was the first part of the Lab, with the rest being creating standard tree methods (such as finding the left, right, and parent nodes given an index, and returning the inorder representation of the tree). The main trouble that my partner and I had with this lab was the left and right functions; though they returned the right index, they were not treating an incorrect index (i.e., one that does not exist within the tree) as an error, and therefore causing problems with the inorder and max_sum methods, both of which used the left and right method in order to do their jobs.
In lecture, we learned about scopes, of how global variables are defined vs local variables, as well as how the variable self, used in all methods to refer to the instance of the class containing the method, can be called other things. In addition, the concept of tracing through iterative and recursive programs was introduced, though for recursion I had already been using that method, except perhaps I traced more steps than necessary.
No comments:
Post a Comment