Monday 24 March 2014

Week 8 - Binary Search Trees

This is the end of week 8, and we just got introduced to a new kind of trees, known as binary search trees. I like trees, and probably Dan knows it, and that's why he is teaching us more trees!

On a more serious note, we just finished a wonderful week where we learned the structure and use of this particular kind of trees. To be honest, there isn't much to learn about their structure. The main learning is in making useful functions or methods to perform particular tasks on/with these trees.

I am really enjoying dealing with these trees! I know some people are really hating it (but I guess I am eco-friendly). Some of the functions that were solved in class were quite interesting. Finding the height of a BST, and finding whether a value is in a BST are two which I enjoyed learning. However, I found the method for deleting a node quite tricky, and can't solve it by myself yet. I seemed to understand it during the lecture, but soon forgot when I came back home. Write before writing this slog, I did some searching on Google and found an algorithm which looks similar to the one that Dan showed us. I hope this will work once I code it. I reviewed the algorithm on the lecture slide, but for some odd reason that seemed quite confusing.

Overall this week was not a bad one. I experimented a lot of things this week with trees in general (not just BSTs). I even made a method which returns the number of leaves in a tree:

def num_leaves(t: Tree) -> int:
    if t is None:
        return 0
   
    if t.children == []:
        return 1

    count = 0
    for child in t.children:
        count += leaf_count(child)

    return count

I am also trying to implement a method which will find and return the average of the values of whole binary tree. But, I am still struggling with that.

Okay, on a different note, I just saw that the handout for Assignment 2 got posted. After reading it for around 10 times, I am yet to understand what we exactly have to do in part 1. I probably have to go Dan's office hours for this.

As we wait for the results of Assignment 1, it's already time to get started with Assignment 2.

Hope the coming week will treat me well.

No comments:

Post a Comment