Sunday, March 22, 2015

Impression on Week 8

    This week we learned more stuff on Binary Search Trees(AKA BST).  It is a tree which can only have up to 2 children.  The one on the left is less than the data in that node, and the one on the right is more than the data in that node, and we are going to learn how to carry out delete and insert method on it, including on how to implement the method ourselves.

    This is way more challenging than I thought it would be.  At first I thought it would just be like any other lab we did before, but without the TA's help, I was a little lost at first, but what is important is I found my way through.  

class BTNode:
    """Binary Tree node."""

    def __init__(self: 'BTNode', data: object,
                 left: 'BTNode'=None, right: 'BTNode'=None) -> None:
        """Create BT node with data and children left and right."""
        self.data, self.left, self.right = data, left, right


class BST:
    """Binary search tree."""

    def __init__(self: 'BST', root: BTNode=None) -> None:
        """Create BST with BTNode root."""
        self._root = root


     The code above is just a to give you a vague idea of what the init method of the code looks like.  As you might have noticed, it has two class, we are using the BTNode class to create BST.  It is kind of similar to what you might be familiar of, a helper function, but in this case, it is not a function, it is a class(so maybe you can call it helper class??).  We are using BTNode to implement BST which is easier to do in a sense of coding.  You will know what I mean once you get your hands on it.

    Well, so much for this week.  Let's behold what challenge lies head next week waiting for us to solve.
    

No comments:

Post a Comment