A tree? Oh, like one of those tree diagrams! That sounds easy to make. Oh, wait. It's not.
At first it seemed like planting and taking care of a real tree would've been easier than learning about trees in Python and recursive methods to make them work. I definitely felt unprepared when I went to my tutorial to get stuck on a question about trees for the whole class. Although I had a lot of trouble grasping the concept of class objects inside other objects of the same class, I decided then and there that trees would not be the end of my programming career. I refused to get defeated by what seems like a simple concept.
You can think of a tree like an elongated list of lists. There is one list that keeps track of other lists (which may or may not keep track of even more lists). This main list and all the other sublists have values that are associated with them. So in a way, trees have more functionality than a list of list of list of etc. Sure, that is not too hard to understand. This is not where I struggled.
The hardest part of trees is the methods that you can implement with them. For example, you can create a method that finds the highest value in the tree. In short, there is a method that searches every node of the tree and returns the highest value among all the nodes. Methods like these are what make trees really tricky. You cannot simply return a max function and get the highest value. Instead, you have to use recursion to search through every node starting from the root all the way to the last leaf. Talk about a whole lot of work.
Sure, implementing this method is not a one-way thing. It is not as simple as plugging in a function and getting the result. But then again, this is exactly what I asked for in my previous posts: I want this course to challenge me with concepts that are not straight-forward. As I take time to better myself in these recursive methods, I will become a better programmer (and in return a better man).
No comments:
Post a Comment