Note: Please mark my object-oriented programming post.
This week we talked about binary search trees. At first I was confused as to why the distinction between regular trees and binary trees was being made but considering the advantages of having a binary search tree, it became a lot clearer. Binary search trees organize data in a such a way that for any node, all the nodes in the left child are less than the value of the node and all of the nodes in the right child are greater than the node value. When first doing the lab, I found that the algorithms did not work if you only considered the left child to be less than the node and the right child to be greater. However, I learned that you must consider that all the nodes the left tree and all the nodes of the right tree must follow this rule in order for search-related algorithms to actually be efficient. Otherwise, you would still have to look through every node.
During the lab, I found surprisingly that the BTNode problems were than the tree problems. I think that since children have None values, it made it harder during the base cases for the recursion algorithms. The regular trees were easier in this regard because the nodes with no children would have an empty list as the next node instead of two None values. You also had to check each of the left and right nodes separately since they were stored in different parameters whereas in a regular tree, there was only one parameter in the object for children.
We also learned about Pre Order, Post Order and In order listing of trees which was not too difficult to learn and understand.
No comments:
Post a Comment