Blog Entry #4: Linked Tree...more trees
Oct 29th
Another week of studying on trees, this week we learned about the linked tree which is a special case of a tree, with branching factor of 1. The data structure is built on one node with the next node that it links to. And we also implemented Stack with linked tree. However, I do have a few questions regards to the application of the linked tree. Since the branching factor is 1, what is the difference of storing the data in a list and a linked tree?
Now moving on this week's exercise, personally I think exercise 5 is fairly easy. Part a requires to recursively set depth to the node and call the same function on its children and add 1 to the new depth. And part b requires to recursively check if both left and right child are empty to determine if the given node is a leaf or internal node, and repeat the process on its children if the given node is an internal node. In addition, I found Monday's lecture very helpful, especially the example with a function inside the function that can be called recursively (sorry if my wording is a little confusing, I can't remember the technique term of this method). When I try the exercise at the beginning, this method did not occur to me and I encountered errors when I attempted to call the set_depth function by calling the whole class.
I'm glad to see that I've been making some progress in this class, and also a little surprised to realize how much I learned in only 6 lectures. At least I'm getting very comfortable coding with recursions. Back in high school, recursion really intimidates me and for one moment I thought I would never be able to apply this logic. But now I finally start to see the convenient of using recursions and how neat and simple the code can be written this way.
Please leave you comment below, feel free to give me any constructive feedback or you can just say HI. :)
No comments:
Post a Comment