For the majority of this course, we've been introduced to many different kinds of commonly used abstract data types such as queue, stack, sack... and so on. An abstract data type is a data type that can be created by a user. This data type has its own behavior, has its own data, and has its own operations that manipulates/interacts with their own data. During this week we learned about a new abstract data type called Trees.
You can imagine a Tree as a data structure with a chain of nodes that can be imagined as a hierarchy. A Tree's nodes store one value each. (i.e. 7) Some nodes lead/refer to other nodes, and some nodes don't refer to any other nodes. Nodes that don't refer to other nodes are called leaves, since they are "childless". All trees have a starting node called a root. Every node in a tree is a descendant of the root. The root itself is the only node in a Tree that doesn't have a parent. Here's an example of a tree with each node being represented using parentheses: (1) has three children, which are (2), (3), and (4). (2) has a child which is (10). All other nodes are childless.
We learned that Tree has very basic operations such as __str__, __contains__, __repr__, and __eq__. During this week we've also learned about some (module level) functions that can be used to manipulate Trees or get information from Trees. These module level functions strongly relate to recursion.
No comments:
Post a Comment