Monday, March 9, 2015

Week 7: Binary Tree and the Assignment

I decided not to go to the class this week because there would be two assignments due the next week: Assignment 2 for CSC148 and for CSC165. But my friends told me it is a bad habit to skip class even the deadline is approaching since then I don't know what is going on next. So I still learned something new:

Binary Tree

Binary tree is a tree that has only 2 branches: the left and the right. One or both can be None. If both are None, then it is a leaf. And itself is a datum.

Sample questions: how to find the depth of the tree?
We need to use recursion to go through every tree and use max() to compare the length of each node in order to get the greater one.

Binary Search Tree

Binary search tree is a tree that is used to search a set of data quickly. Since it is binary, it also contains only 2 branches: the left and the right. the left one is normally the smaller one while the right one is the greater one. This structure saves half of the time to find a number: if the number is greater than the datum, then it searches the right side of the subtree, or it is less, then it searches the left side. Definitely, if it is equal to the datum, then it is the number we need to find.

About the Assignment

It was much harder than I had expected. I thought it could be conquered in less than 24 hours, but the truth was, even after 48 hours, I was still struggling on the minimax: a game strategy that requires recursion.
So I decided to go to the office hour to ask the professor. He told me something basic yet important: Read the starter code! I had never read the starter code, and therefore it caused a problem when I used the help function. For example, I thought 'apply_move()' could work but it actually did nothing in my code. It didn't update the code automatically, which I expected. After a complete comprehension of the starter code, I changed it into: 'new_state = apply_move()' and I used the new_state to go though the next step. And then it works! It did the function that I expected. So in this lesson, I learn something new: Don't rush to start writing, read the instructions and the start code thoroughly instead.

No comments:

Post a Comment