Sunday, 16 February 2014

Post #4: Assignment I and Trees!

I forgot to post last week so I wanted to quickly mention that Assignment I is over! I finished it a week before the due date, so I had plenty of room to tweak everything. My overall thoughts are pretty positive, the assignment was an interesting concept and posed a challenged for the most part! The most difficult part was not actually coding, rather, it was the process of understanding how to approach the assignment (notably step 5). Other than that, I thought it was great and I managed to get it done!

So this week (6) we briefly learned about the Tree ADT.  By definition, they are a data structure in which data is linked through a hierarchy of linked nodes.

We also learned a bunch of terminology relevant to this ADT such as "leaf" (a node with no children--e.g. [12] in the image) and "root" (which distinguishes a node, e.g. [50]).

It is easier to think of tree recursively; a Tree is a collection of nodes (which has a value) that refers to children nodes (which also has a value). These children can either either create a new tree--recursively--or just be a leaf.

For example, if we look at the image to the left we can see that the first tree consists of the root [50] with children [17] and [76] -- recursively, we can see that [17] also is a root of a tree that has a two children.. and so on.

Trees can be accessed and manipulated by traversing through the data. What we learned in lecture were three methods of doing so:

In-order traversal -- Which recursively visit the left subtree, the root, then the right subtree.
Pre-order traversal -- Which recursively visits the root, the left subtree, then the right subtree. 
Post-order traversal   -- Which recursively visit the left subtree, then the right subtree, then the root.

Pretty cool stuff! Looking forward to understanding the implementation of trees.

It's reading week! Yay and Nay! Yay because I don't have to wake up at 6:30 to make my train, but nay because I have the most amount of work I've ever had in first year. An assignment for each course! Yup, assignment II has been announced. I've skimmed over it, but I haven't started. It seems like it involves implementing trees to work with regex regular expressions (which I am vaguely familiar with). We also have Test 1 coming up, I am pretty nervous but I think I will do well if I study what I am not great with (which I feel is recursion currently).

Good luck to me!


No comments:

Post a Comment