In week 7 we learned about the data class Binary Trees. To explain what a Binary Tree is I'll first have to explain what a Tree is. A Tree is a data class which we had learned about in previous weeks. Trees start at a single node which is at the "top" of the tree. This node contains some type of information, and also has "children", which are other nodes. These children also contain data, and can also have children of their own. Each node within the Tree functions as a starting node for its own "sub-tree", which can be accessed the same way as the original node. Trees are a class which can be used to give data a structural organization, and link certain pieces of data together (parent-children relationship). Additionally, all the data in a tree can be accessed via recursive functions, which go through the tree until there are no children.
A Binary Tree is a specific type of Tree, which has the unique property that each node has a maximum of two children. This gives the data a more organized structure than a normal tree which facilitates some specific functions. Two examples we were shown in class are Binary Expression Trees and Binary Search Trees. With Binary Expression Trees, each interior node (a node with children) is an arithmetic operator, and any leaves (nodes without children) contain numbers. A recursive function can then be used to evaluate the numbers using the arithmetic expression until one reaches the top of the tree. For Binary Search Trees, each node contains a number, and the left child is always less than the value at that node, and the right child is always greater. This allows for numbers to be searched for very quickly.
Binary Trees seem to be a very useful and efficient way to store data. By limiting the number of children to two, Binary Trees have a much more rigid structure than normal trees. This allows for efficient storage and retrieval of data. However, though they are efficient, Binary Trees are only useful for very specific sets of data. For example, Binary Search Trees are incredibly efficient for searching a group of numbers, because with each step down the tree one can eliminate a significant amount of the remaining data. However, this class only works for a set of data containing only numbers, and is only really useful for searching data sets and related functions. Though Binary Trees are very good data storage systems, the fact that they are limited to specific types of data reduces their usefulness to a computer scientist.
No comments:
Post a Comment