Saturday, 4 April 2015

Week 10 (week nine impressions)

Last week we had our assignment and this week we had our test.  I really with the strike was over so I could have talked to my TA and asked him for help on the assignment.  In class, we continued studying BSTNodes.  The insert function we looked at in lecture was similar to previous functions we have seen before.

def insert(node, data):
    ’’’ (BTNode, object) -> BTNode
    Insert data starting at node, and return root.
    ’’’
    return_node = node
    if not node:
        return_node = BTNode(data)
    elif data < node.data:
        node.left = insert(node.left, data)
    elif data > node.data:
        node.right = insert(node.right, data)
    else: # nothing to do
        pass
    return return_node

This code looks similar to that of the bst_contains function (mentioned in week 8), as it checks whether data is greater than or less than the node before recursively calling itself on the left or right node.

We also briefly covered the assert statement, which basically just raises an error if and expression is False.  We didnt study that much else in class this week because we had the test.  The lab for the week covered inserting objects (e.g. values and strings) into a btnode and a delete function different from the one in class, balancing the deletions on each side of the tree.


I felt pretty confident about the test we had last week.  The questions were similar to what was in the labs, nothing very surprising.

No comments:

Post a Comment