This week was the Midterm for 148, as well as an exploration of trees, data structures that are organized recursively. Due to its recursive nature, trees are best created and read recursively, although they can be converted back to lists using three methods (which create lists with the same elements but in different order): preorder, inorder and postorder. These methods are known as traversal methods and are ways to step through all nodes once each, using only the connections between parent and children nodes. Though at first I didn't know of why anyone would prefer using a data structure such as a tree over just a regular list, I learned many applications for trees this week.
One of the best uses of a tree is to search for values, as demonstrated earlier in an exercise. By making sure that one branch of the tree is larger than the root node, and the other smaller, you can significantly speed up the search process, as long as converting the initial set of values into such a tree is efficient enough.
No comments:
Post a Comment