trees are an interesting ADT. that is because although in code they are depicted of as an unorganized nested list, however their true structure can only be revealed in a diagram.
a property of such a diagram includes:
nodes
the root
path
length
leaf
internal node
height
depth
arity.
even though the "look" like an unorganized list, in order to construct a tree object using OOP, (at least ) python recognizes key worlds "value" as the root and "children" as its branches when declared in the initializer.
although we have not encountered a situation where a tree can be used to solve real computer science problems, it is not a stretch to say that there are "ideas" that can be represented by trees if you were to see how to sort (or, traverse) through one:
this goes back to the idea that a tree in python can look like an unorganized nested list. as such, one should build a recursive function to traverse through it.
there are (so far) two implementations of functions that we have worked on the the labs, however, both of which have in common of: 1) making a recursion call at each depth, 2) for loop iterating through each element within that depth.
as such, since an universal algorithm is established above, one can easily see that, at the very least, a tree can be used to represent directories and subdirectories of information. using folders and subfolders in our computer is a classic example.
even though (at our current level of computer science) we have only seen numbers in each node, i firmly believe that the use of the properties of implementing a tree can become very useful when storing information in a computer that is just as complex as the structure of a tree itself.
No comments:
Post a Comment