Tree
A tall plant that lives a long time.
A tree is a connected graph with no cycles. One of its vertices is designated to be the root. If not, then it's a free tree instead of a rooted tree. A group of trees is a forest.
If you add an edge to a tree, a cycle is created. If you remove an edge from a tree, it's disconnected.
Trees pop up in many algorithms because they're great at representing decisions that branch off into several outcomes. The solution to a certain problem may be cleverly equated to traversing a tree in a particular way.
Trees are also good for visualizing the steps of a recursive algorithm.
When you play a game against a computer player, it may be the case that its artificial intelligence is based on a decision tree program that analyzes the state of the game to optimize strategy, even considering probabilities when there's luck involved. However, playing too many steps ahead can still be computationally difficult so the decision tree may have a cap on its height.
Uniqueness of paths
Here's a super-important property about trees... don't forget it! For any \(2\) vertices in a tree, there is exactly \(1\) path between them. Therefore, for any \(2\) vertices in a tree, there is only \(1\) way to travel between them. That path connecting them is unique.
Number of edges
It is true for every tree that the number of edges is exactly \(1\) fewer than the number of vertices.
Rooted tree
Rooted trees are typically drawn with the root at the top and all other vertices are organized into lower levels, each defined by their distance from the root. The distance between two vertices is defined as the number of edges in the shortest path between them. The height of a rooted tree is simply the greatest distance any vertex has from the root.
Let's talk a bit about the vertices in a rooted tree. Every non-root vertex in a rooted tree has exactly \(1\) parent (of which it is a child), which is the unique vertex that is visited immediately after it in a path to the root. All the vertices that come after a non-root vertex in a path to the root are its ancestors (of which it is a descendant). Rooted trees are drawn such that ancestors appear above their descendants. A vertex without children is a leaf. A vertex without a parent is the root. Vertices with the same parent are siblings.
A subtree is a rooted tree contained entirely within another rooted tree. To build a subtree, pick any vertex in a rooted tree. That vertex and all its descendants together make up a new rooted tree, rooted at the vertex that was picked.
Free tree
A vertex in a free tree is a leaf if its degree is \(1.\) Also, when a free tree consists of a single vertex, that vertex is a leaf. A vertex in a free tree is internal if its degree is \(\geq 2.\)
Here's a statement you might find useful. Any free tree with at least \(2\) vertices has at least \(2\) leaves: