Tuesday, 7 April 2015

Review on Week 7

Just before reading week, Danny introduced us to trees and drew us one using a Turtle. This week, we go further in depth and really define a tree, from its roots to its leaves. We also defined pre-order, in-order, and post-order search when traversing a tree, which is really straightforward with this illustration:
In-order:
Post-order:

 Pre-order:
Images taken off http://en.wikipedia.org/wiki/Tree_traversal


Now to actually traverse the tree in the code to search for the right nodes or alter them can be very complicated, but it can be done using recursion. Recursion is so simple yet so complex at the same time, like tracing out a tree is so simple to us humans, yet for a computer it can be quite tricky! It does require lots of scribbling and mapping stuff out with pen and paper. I really find the handouts to be useful in helping me understand the lecture material better and it engages me so my mind doesn't wander off. And I think with practice makes perfect and soon recursion would be a piece of cake!

However the lab did seem to be a challenge for me as I got stuck at the second function. I couldn't figure out, for the life of me, how to build a list recursively as my method would pass define the list as empty every time it passes through the function recursively. But after some help from the TA, I finally got it to work and learned something new, which is always great!

No comments:

Post a Comment