CSC148H1 Lecture Notes - Lecture 22: Binary Tree, Branching Factor, Eval
katrinasavvy and 38715 others unlocked
1
CSC148H1 Full Course Notes
Verified Note
1 document
Document Summary
References: code seen in the pictures can be on the csc148 website: http://www. teach. cs. toronto. edu/~csc148h/winter. One approach to binarytree would be to make it subclass of tree, but there are some design considerations: any client code that uses tree would be required not to violate the branching factor of binarytree. 1 way to achieve this is to make tree immutable: make sure there is no way to change children or value, have subclasses that might be mutable. However, it is easier to make a completely separate binarytree. Change generic tree design self. left, self. right = left, right: 2 children named left and right. Standard special methods: __eq_, __str_, __repr__ Implemented contains on linked lists, nested python lists, general trees. Modify this function so it becomes a method. Height = 1 + the maximum path length in a tree. A node also has a height, which is 1 + the maximum path length of the tree rooted at that node.