A tree is a non-linear data structure that is used in computer science to store information. It's commonly used to store data that maintains relationships, particularly if the relationships form a hierarchy. Trees are also simple to search (diagram for array sorting algorithms in the Understanding sort algorithms section) shows us that many trees have an O(log n) time complexity with operations in trees). For many problems, trees are the best solution because of how they reference hierarchical data. Trees are combinations of nodes that don't make a cycle.
Each tree is made up of elements called nodes. We start at the root node (the yellow box labeled root in the binary trees figure below). There is a left and a right reference pointer (numbers 2 and 7, in our case ) and a data element (the number 1, in this case) within each node. As a tree grows, the...